URAL 1515 Cashmaster 数学题
来源:互联网 发布:淘宝的主营业务有哪些 编辑:程序博客网 时间:2024/05/22 17:13
1515. Cashmaster
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Background
Once upon a time former petty bureaucrat, nowadays the Minister of Finance of the Soviet Federation, Victor Thiefton considered, that he had stolen so much money during the first half of his life, that it will be enough for the last half also (this story is fully described in the problem "Crime and punishment"). As a result of this conclusion Victor intended to devote himself to immortalizing of his good name in national opinion.
Being the Minister of Finance, Mr. Thiefton knew perfectly, that the most gratifying thing to the human eye was a banknote. So he decided to print his noble face on the banknotes issued by his Ministry.
But even Victor grasped, that it would be wrong to print his face on the banknotes, which had been already issued. Therefore a propitious occasion was given to Mr. Thiefton to carry out a financial reform - to issue a banknote of some new denomination with his face on the both sides of it.
Problem
The time came to define a denomination of the new banknote, i.e. a positive integer, which should be printed on it. For a start, Victor took all the banknotes of different denominations, which had been already issued till that moment, and put them in ascending order. It appeared, that there were exactly N such banknotes, and a denomination of each of them was Di dollars. It seemed he might take any of still unused denomination. But ambitious Mr. Thiefton did not want the new banknote's denomination to be presented as a sum of the denominations of the banknotes, which are already issued...
And here Victor realized, that he had nearly failed to bear one extremely important thing in mind. The point was that the planned emission (i.e. an issue of a new batch of money) would inevitably cause inflation growth, which, in its turn, might lead to a devaluation of Mr. Thiefton capital, that was plundered with such a great effort. Therefore the desired denomination should be minimized.
Input
The first line contains the integer number N (1 ≤ N ≤ 100). The second line contains N integer numbers Di (1 ≤ Di ≤ 106; Di < Di+1).
Output
You should output the desired denomination of the new banknote.
Sample
51 2 4 9 100
8
Notes
In the sample, the denominations 3, 5, 6 and 7 may be presented as sums of the denominations of the banknotes, which are already issued (3 = 1 + 2, 5 = 1 + 4, 6 = 2 + 4, 7 = 1 + 2 + 4), whereas the denomination 8 can not be present as such sum.
题意:从小到大输入n个数,这n个数每个数只用一次,可以通过加法组成很多数。然后从1开始判断这些数无法组成的最小的一个数。
做法:如果开头不是1,那输出就是1了,因为无法通过别的数来获得1。如果开头是1,第二个不是2那就输出2,也是因为不能通过别的数加成2了。 那么有了基础就可以开始递推了。假设 前x-1个可以获得任意小于 前x-1个数的和 的数。那么假设x-1个数的和
大于等于第x个数-1,那么就是从1到x-1个数都可以组成。如果不行直接输出前x-1个数的和就好了。
#include<stdio.h>int main(){int a,n,sum;while(scanf("%d",&n)!=EOF){int flag=1;int sum=0;for(int i=0;i<n;i++){scanf("%d",&a);if(sum<a-1&&flag){printf("%d\n",sum+1);flag=0;}sum+=a;}if(flag)printf("%d\n",sum+1);}return 0;}
0 0
- URAL 1515 Cashmaster 数学题
- URAL 1515. Cashmaster (数学啊 )
- 【Ural】1066 数学题 Garland
- URAL 1068. Sum (小学数学题)
- URAL 1567. SMS-spam (小学数学题)
- URAL 2001 Mathematicians and Berries (小学数学题)
- URAL 2070. Interesting Numbers(素数打表 数学题)
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- 数学题
- sort和qsort一些用法的总结
- xcode6本地化教程
- error: '>>' should be '> >' within a nested template argument list
- lvm 系统函数API应用
- 幸福
- URAL 1515 Cashmaster 数学题
- Hack3--Creating a custom ViewGroup
- combo实现年、月展示
- 结合美团下单率预测详解机器学习中的数据清洗与特征处理
- ORA-00604: 问题处理
- Android4.4 wpa_supplicant深入分析之wpa_supplicant初始化流程续
- CSS float浮动的深入研究、详解及拓展(一)
- 阿里巴巴集团web安全标准Ver1.4
- Linux驱动程序安装步骤(包括PC上及开发板上)