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 ...
随机推荐
- C++—函数
一.函数的基本知识 要使用C++函数,必须完成一下工作: (1)提供函数定义: (2)提供函数原型: (3)调用函数. 1.定义函数 可以将函数分为两类,有返回值的函数和没有返回值的函数.没有返回值的 ...
- 解决淘宝sui插件后退bug
淘宝的sui插件在微信里,第一次访问没有问题,跳转走以后,再后退回来, 插件就无法正常加载. 一下是官方给出的说法 切换到的新页面中的 js 不执行 由于浏览器安全性考虑的限制以及可能的 js 重复执 ...
- Css3_浏览器支持
#box{ color:red; ⁄* 所有浏览器都支持 *⁄ color:red !important; ⁄* Firefox.IE7支持 *⁄ _color:re ...
- 转!!数据库 第一范式(1NF) 第二范式(2NF) 第三范式(3NF)的 联系和区别
范式:英文名称是 Normal Form,它是英国人 E.F.Codd(关系数据库的老祖宗)在上个世纪70年代提出关系数据库模型后总结出来的,范式是关系数据库理论的基础,也是我们在设计数据库结构过程中 ...
- 转!!java中关键字volatile的作用
用在多线程,同步变量. 线程为了提高效率,将某成员变量(如A)拷贝了一份(如B),线程中对A的访问其实访问的是B.只在某些动作时才进行A和B的同步.因此存在A和B不一致的情况.volatile就是用来 ...
- JSON和JSONP区别和联系
由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...
- Windows Server 2012 (2008) 忘记密码重置方法 Windows 10 忘记密码
要使用windows server 2012安装DVD,选择光盘引导进入 进入修复系统---命令提示符---切换目录至系统目录--执行move命令 先备份 utilman.exe(他就是这个程 ...
- GATK原理及流程
用GATK跑了很久的流程,但还是不知道它的原理,现在项目要深入,没有流程可用,一切都要手动,所以必须开始着手了解GATK运行的原理,必须要知道需要输入什么,基本的算法,输出是什么. 参见: GATK使 ...
- [Java] 获取本月周次和日期时间段信息
package com.wdcloud.monitoring.common; import java.text.SimpleDateFormat; import java.util.ArrayList ...
- Redis与Java - 数据结构
Redis与Java 标签 : Java与NoSQL Redis(REmote DIctionary Server) is an open source (BSD licensed), in-memo ...