正整数
2015-07-26 20:04
169 查看
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84077#problem/A
题目:
Description
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimumunfortunate sum?
Input
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.
The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Output
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
Sample Input
Input
Output
分析:有1输出-1,没有1输出1.
题目:
Description
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimumunfortunate sum?
Input
The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.
The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.
Output
Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print - 1.
Sample Input
Input
5 1 2 3 4 5
Output
-1 题意:问n个数所不能组成的最小的正整数是多少,如果都能组成输出-1
分析:有1输出-1,没有1输出1.
#include<iostream> using namespace std; int a[1000]; int main() { int t,i; cin>>t for(i=0;i<t;i++) cin>>a[i]; for(i=0;i<t;i++) if(a[i]==1) {cout<<-1<<endl; break;} if(i==t) cout<<1<<endl; return 0; }
相关文章推荐
- HDU4287 字典树
- 找出java代码中占用cpu过多问题
- UVA 401
- Automatic Editing
- CSS元素分类
- LightOJ 1141 Program E
- UVA 10474 Where is the Marble?
- 由Handler引发的内存泄漏的思考
- 【Prism】MEF版UIComposition
- HDU 3973 AC's String 字符串哈希
- iostream
- sift是图像匹配的非常经典的算法
- DFS-POJ-1321-棋盘问题
- 【BMI指数计算器V2.0】项目实战
- GestureOverlayView(手势识别2)
- shape layer-list selector使用
- Watch The Movie(严格限制数量的二维费用背包)
- 在空白处填充程序3
- G - Balanced Lineup - poj3264(区间查询)
- LeetCode---(160)Intersection of Two Linked Lists判断两个链表是否相交