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 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
5
1 2 3 4 5
-1
分析:
这题只用两种可能,就是输入有1与无1,有1时就找不到sum,所以输出-1;无1时有最小sum为1,即输出为1.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,i;
while(scanf("%d",&n)==1&&n)
{
int f=0;
for(i=0;i<n;i++)
{
int x;
scanf("%d",&x);
if(x==1)
f=1;
}
if(!f)
printf("1\n");
else
printf("-1\n");
}
return 0;
}
Problem A CodeForces 560A的更多相关文章
- Problem - D - Codeforces Fix a Tree
Problem - D - Codeforces Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作 ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
随机推荐
- HttpURLConnection请求接口
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataOutputStream; ...
- Bootstrap文本对齐风格
在排版中离不开文本的对齐方式.在CSS中常常使用text-align来实现文本的对齐风格的设置.其中主要有四种风格: ☑ 左对齐,取值left ☑ 居中对齐,取值center ☑ 右对齐,取值r ...
- redhat 6.4 yum 本地配置简记
准备工作 ----------------------------------------------------------------------------- 1. 加载光驱 将iso镜像文件 ...
- c++11 其他特性(一)
c++11还增加了许多有用的特性,比如: 1. 委托构造函数 如果一个类含有很多构造函数,这些构造函数有一些重复的地方,比如: class A{ public: A(){}; A(int a){ a_ ...
- Hbase之取出行数据指定部分+版本控制(类似MySQL的Limit)
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CellScanner; import org. ...
- 晒幸福, qq空间晒法
qq空间晒法 1.成为老婆之后,还是说新交的女朋友,这会让女朋友感动
- SAP中寄售处理
寄售分两种: 1, 供应商提供货物,我们销售 2,我们提供货物,寄售商销售 [@more@] 1, 供应商提供货物,我们销售 创建PO,购买寄售货物,categories维护成K,然后收货即可. 2, ...
- 【NOIP2015】推销员
推(chuan)销员 分析 这里主要阐述一下我的分析思路. 看起来挺直观的. 最初的想法,我们枚举每一个最远点mxp的位置,然后对之前的a进行排序. 那么以mxp为最远点,选x个的最大疲劳值为: 这样 ...
- MySQL 存储php中json_encode格式中文问题及解决
MySQL 存储php中json_encode格式信息 ,遇到中文时, 会变成一堆类似uxxxx信息. 1. 原因分析:在存储到数据库时!MySQL 不会存储 unicode 字符: MySQL 仅 ...
- hdu----(3118)Arbiter(构造二分图)
Arbiter Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...