In Nowhere town, people use “coin and slot” as their money. There are 2 types of coins called size1 and size2. Size2 coin is twice the thickness of size1. People stack their coins in slots and use them as money. There are many size of slots. The slot of size n is able to stack up n size1 coins. Only filled- up slot is considered as legal money. The value of each filled- up slot is the distinct ways its can stack coins inside. For example, for size- 1 slot, there is only one way to stack a single size1 coin inside. For size- 2 slot, there are 2 ways to stack two size1 coins or one size2 coin inside. And for size- 5 slot, there are 8 ways to stack coins inside, which can be illustrated as follow: 1 1 1 1 1, 1 1 1 2, 1 1 2 1, 1 2 1 1, 2 1 1 1, 1 2 2, 2 1 2, 2 2 1. So the value of filled up slot with size- 1, size- 2 and size- 5 are 1, 2 and 8 (monetary) units respectively (regardless of the type of coins or the ways they are stacked).
    Mr. Thinktwice is an owner of a grocery store in this town. He noticed that customers are likely to go to the shop that can return the (money) change in the form that suits their customer. And from his little survey, he found that most customers would like to get their amount of change in the form according to these 2 simple constraints.

  1. The number of slots is minimum.
  2. The size of each slot must be different from each other by at least 2. —This means that customers does not want any slots with the same size and it will be easier for them to distinguish these differences if the sizes are not too close.
        So Mr. Thinktwice ask you to write a program that can give him a series of slot sizes for a
    given amount of change according to the previous constraints. Moreover, the series must be sorted in
    descending order. For more specific, any amount of change can be written in this formula.
    X=∑i=1nT(si)=T(s1)+⋅⋅⋅+T(si)+⋅⋅⋅+T(sn),s1≫s2≫⋅⋅⋅≫si≫⋅⋅⋅≫sn>0X = \sum_{i=1}^nT(s_i)\\ = T(s1) + · · · + T(si) + · · · + T(sn), s1 ≫ s2 ≫ · · · ≫ si ≫ · · · ≫ sn > 0X=∑i=1n​T(si​)=T(s1)+⋅⋅⋅+T(si)+⋅⋅⋅+T(sn),s1≫s2≫⋅⋅⋅≫si≫⋅⋅⋅≫sn>0
    where
        X is an amount of change.
        n is the total number of slot.
        si is the size of i-th slot.
        T is a function mapping from a slot size to a number of distinct ways of stacking coins. and when j ≫ k ≡ j ≥ k + 2
        For example :
                 10 = T(5) + T(2)= 8 + 2
1, 000, 000 = T(29) + T(25) + T(23) + T(11) + T(9)= 832, 040 + 121, 393 + 46, 368 + 144 + 55

Input
Input is a standard input which contains a set of integer. Each line of the input is an amount of change which represents by a positive integer less than or equal to 5,000,000,000,000,000,000 or 5 × 1018. The input is terminated when the EOF (End- Of- File) is reached.
Output
For each amount of change, generate 4 lines of output data. The first line is the amount of change itself. The second line is a series of slot sizes (in descending order) separated by spaces. (The maximum slot size is less than or equal to 90.) The third line is a series of corresponding slot values. The fourth line is a blank line.
Sample Input
1
10
1000000
Sample Output
1
1
1

10
5 2
8 2

1000000
29 25 23 11 9
832040 121393 46368 144 55

问题链接:UVA1258 LA4721 Nowhere Money
问题简述:(略)
问题分析:数学计算问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的Java语言程序如下:

/* UVA1258 LA4721 Nowhere Money */#include <bits/stdc++.h>using namespace std;typedef long long LL ;
const int N = 90;
LL a[N + 1], b[N + 1];
int flag[N + 1];void calc(LL n, int m)
{if (n == 0 || m < 0)return;else if(a[m] <= n) {flag[m] = 1;calc(n - a[m], m - 1);} elsecalc(n, m - 1);
}int main()
{a[0] = 0;a[1] = 1;a[2] = 2;for (int i = 3; i <= N; i++)a[i] = a[i - 2] + a[i - 1];LL n;while (~scanf("%lld", &n)) {memset(flag, 0, sizeof flag);calc(n, N);int cnt = 0;for (int i = N; i >= 0; i--)if (flag[i]) b[cnt++] = i;printf("%lld\n", n);for (int i = 0; i < cnt; i++)printf("%lld ", b[i]);printf("\n");for (int i = 0; i < cnt; i++)printf("%lld ", a[b[i]]);printf("\n\n");}return 0;
}

UVA1258 LA4721 Nowhere Money【数学计算】相关推荐

  1. js函数语法:ASCII 码的相互转换,字符串操作,数学计算

    ASCII 码的相互转换 for (let i = 'a'.charCodeAt(); i <= 'z'.charCodeAt(); i++) {a.push(String.fromCharCo ...

  2. P4588 [TJOI2018]数学计算(线段树维护区间乘和单点修改)

    P4588 [TJOI2018]数学计算 刚看到这题根本每想到用线段树,直接每次记录计算结果然后找到要除的数字就好了呗 但是!你会注意到,如果连续乘很多很多次,然后再除的话,如果不取模会爆 long ...

  3. MATLAB数学计算与工程分析范例教程,MATLAB数学计算与工程分析范例教程

    基本信息 书名:MATLAB数学计算与工程分析范例教程 定价:28.00元 作者:石博强,赵金 编著 出版社:中国铁道出版社 出版日期:2005-05-01 ISBN:9787#113057596 字 ...

  4. Shell脚本笔记(三)shell中的数学计算

    shell中的数学计算 一.使用方括号 #!/bin/bash a=10 b=29 c=88res=$[$a * ($c-$b)] echo $res 二.使用(()) echo $((1+9)) ( ...

  5. python数值运算答案_笨方法学Python 习题3:数字和数学计算

    数字和数学计算 print("I will now count my chickens") print("Hens",25+30/6) print(" ...

  6. 用计算机计算的手抄报内容,关于数学计算手抄报

    开办手抄报对学生是一项综合性很强的实践活动.下面是学习啦小编为大家带来的关于数学计算手抄报,希望大家喜欢. 数学计算手抄报的图片欣赏 数学计算手抄报图一 数学计算手抄报图二 数学计算手抄报图三 数学计 ...

  7. php+数学计算公式,PHP数学计算函数总结

    PHP数学计算函数总结 发布于 2015-01-21 16:53:26 | 189 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertext Preproc ...

  8. 《“笨办法”学Python(第3版)》——习题3 数字和数学计算

    本节书摘来自异步社区<"笨办法"学Python(第3版)>一书中的习题3,作者[美]Zed A. Shaw,王巍巍 译,更多章节内容可以访问云栖社区"异步社区 ...

  9. R开发(part2)--R语言中的数学计算

    学习笔记,仅供参考,有错必纠 参考自:<R的极客理想>-- 张丹 文章目录 R开发 R语言中的数学计算 对数 加权平均.连乘.差分.秩.任意数.全体数 阶乘.组合.排列 累加.累乘.最小累 ...

最新文章

  1. Kotlin 越来越牛逼了!学Java都我想转了!
  2. 英语语法---分词短语详解
  3. android studio 设置控制台字体大小
  4. PHP开发学习-Apache+PHP+MySQL环境搭建
  5. 2020国货品牌力发展报告
  6. docker run后台启动命令_Docker命令-docker run
  7. 计算机组成原理固件,计算机组成原理(A卷)
  8. 南宁计算机职业学校地址,南宁市第三职业技术学校
  9. 逸管家:别只共享单车,互联网时代还可以共享人才
  10. Java反射获取Android系统属性值
  11. 课时2 一些默认样式
  12. [翻译]ChipMunk 2D 游戏重力引擎
  13. KITTI Benchmark原理_距离误差百分数
  14. c51间隔点亮c语言编程,51系列单片机C语言编程
  15. jQuery Validate插件验证
  16. Yingye Zhu‘s Luogu Background
  17. 网络编程——CS模型(总结)
  18. 两波形相位差的计算值_国际学科备考系列A-level物理:相位和相位差的数学解释及物理应用...
  19. HIVE 实现均匀抽样
  20. html5单位转换器,液体单位在线换算工具

热门文章

  1. 2020-04-27 三种内存屏障 acquire barrier / release barrier / full barrier
  2. 奥特曼在银行里下象棋的梗
  3. Ubuntu 安装 TPM-2.0 TSS 软件栈
  4. 使用gsds绘制基因结构图_使用SnapGene viewer绘制比较基因簇结构图
  5. 关于更新内容次序问题
  6. Android中Bitmap缓存池
  7. java与物联网_java和php做物联网哪个好
  8. spring mvc4 html访问,Spring 页面重定向例子
  9. java split 坑_Java坑锦集一 - split函数
  10. Python 之 运算符