Currency System in Geraldion (Codeforces 560A)

A  Currency System in Geraldion

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 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 ≤ ai ≤ 106,所以能给出的最小数就是1.因此N个数中有1,输出1;否则输出-1.

代码:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 int n[1000];
 8
 9 int main ()
10 {
11     int n, m;
12     while(scanf("%d",&n)!=EOF)
13     {
14         int  f=0;
15         for(int i=0; i<=n; i++)
16         {
17
18             scanf("%d",&m);
19             if (m==1)    f=1;
20         }
21         if(f)
22             printf("-1\n");
23         else
24             printf("1\n");
25     }
26     return 0;
27 }

心得:

这道题完全要靠理解题意,题意没有理解怎么会做出题来呢?这么简单的一道题光看题就看了那么久,才理解题目的意思。经过几次比赛发现英语实在是太差了,要好好学习英语了。加油吧。

时间: 2024-11-10 13:08:19

Currency System in Geraldion (Codeforces 560A)的相关文章

【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/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,

Codeforces Round #313 A. Currency System in Geraldion

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 mone

Currency System in Geraldion

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=201542 题意: 输入一个数n,表示几种不同面值的纸币.输入那组纸币的面值,问不能组成的价值中最小的是多少,如果所有价值都可以组成,则输出-1. 案例: Inpu 5 1 2 3 4 5 Outpu -1 思路分析: 当有面值为1的纸币时,你就会发现可以用1组成任意价值的钱.所以在1存在时直接输出-1. 当没有面值为1的纸币时,任何面值都无法组成1. 所以直

Problem A CodeForces 560A

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 mone

Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560 水笔场... A. Currency System in Geraldion time limit per test:2 seconds memory limit per test:256 megabytes A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several va

Codeforces Round #313 (Div. 2)

A. Currency System in Geraldion 刚开始以为是什么动态规划,直接在那里叫这可怎么办?后来又想到如果10里面的数可以拼出来,那么大的也可以拼出来了,于是这样写就过了.今天早上一看人家的代码,才发现如果一可以拼出来,那么其他都可以拼出来.所以只需要将输入的数排序,第一个是不是一考虑一下就可以了.自己思维还是不够. #include<bits/stdc++.h> using namespace std; int a[1024],dp[1000000+5]; int ma

Codeforces Round #313 (Div. 2) 解题报告

A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假设这些纸币的最小值大于1,那么它所不能组成的最小面额就是1.所以自学求最小值就可以. 我的代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue

Codeforces Round #313 (Div. 2)(A,B,C,D)

A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值,若所有面值的都能表示,输出-1. 思路:水题,就是看看有没有面值为1的货币,如果有的话,所有面值的货币都可以通过1的累加得到,如果没有的话,最小的不能表示的就当然是1辣. #include <stdio.h> #include <math.h> #include <string.h> #include <stdli

chd校内选拔赛题目+题解

题目链接   A. Currency System in Geraldion 有1时,所有大于等于1的数都可由1组成.没有1时,最小不幸的数就是1. 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 void solve(){ 6 int n,x; 7 scanf("%d",&n); 8 int flag = 0; 9