货币问题
2015-07-24 20:47
302 查看
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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 minimum unfortunate 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就输出1即行。但是值得注意的就是后面的FOR循环不能写前面那For循环的变量用相同的,这样会导致AC不了。
程序代码:
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 minimum unfortunate 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
程序分析:此题的大意就是用哪几种货币能够表达所以的货币。这样就可以知道1可以表达任意货币,所以输入的数据只要有1就可以输出-1,如果一个数组里没有1就输出1即行。但是值得注意的就是后面的FOR循环不能写前面那For循环的变量用相同的,这样会导致AC不了。
程序代码:
#include<iostream> using namespace std; int a[1006]; int main() { int n,flag=1; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int k=0;k<n;k++) { if(a[k]==1) { flag=0; break; } } if(flag) cout<<"1"<<endl; else cout<<"-1"<<endl; return 0; }
相关文章推荐
- facebook 开源文件传输 lib
- Java集合框架
- 工程日记的重要性
- Veriog_Notes_Chapter 2
- js把日期字符串转换成时间戳
- IntelliJ IDEA 快捷键
- 泛型和枚举
- 【数据库】Truncate的用法
- A Bug's Life - poj2492
- Linux内核学习方法
- web实现验证码
- hdu 5305 Friends(2015多校第二场第6题)记忆化搜索
- Java中的一些错误提示原因
- 【iOS开发之Objective-C】单例的创建
- 暑假夯实安卓基础系列二
- 求和
- hdu 5280 Senior's Array(最大子段和)
- hdoj 2035 人见人爱A^B
- 【转】Android世界的Swift - Kotlin语言
- Big Number