codeforce 560 A Currency System in Geraldion

来源:互联网 发布:软件定义物联网 编辑:程序博客网 时间:2024/04/29 23:36

题目链接:http://codeforces.com/problemset/problem/560/A


A. Currency System in Geraldion
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
51 2 3 4 5
output
-1



卧槽,这题谁出的,英文学的渣简直就是罪恶。题目看了好久没读懂,以为很难。读了好几遍才发现简直是弱智题。

意思是说:要有一套纸币体系,包含n种币值(a1,a2,…,an.均为正整数),问是否给出的任意数值(正整数)纸币均能表达,若都能则输出“-1”;若存在不能表达的币值,则输出其中最小的值。

思路:如果给出的基础币值体系中含有1,那么试问有哪个正整数不能表示出来呢?而1最小的正整数,本身又不能由其他比它大的数字表示出来,所以只要不含1,那么1肯定不能表示出来。。。所以最终答案不是1就是-1。。。



#include <iostream>#include <cstdio>using namespace std;int main(){    //freopen("input.txt","r",stdin);    int n;    int a[1010];    while(~scanf("%d",&n))    {        int flag=0;        for(int i=1; i<=n; i++)        {            scanf("%d",&a[i]);            if(a[i]==1)                flag=1;        }        if(flag)            cout<<"-1"<<endl;        else            cout<<"1"<<endl;    }    return 0;}


0 0
原创粉丝点击