博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015 HUAS Summer Contest#1~A
阅读量:4593 次
发布时间:2019-06-09

本文共 1264 字,大约阅读时间需要 4 分钟。

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
 
解题思路:此题看着题目感觉很复杂,其实很简单,关键是要看懂题意。总的来说就是看输入的数字中有没有1,若有就输出-1;没有就输出1.直接在数组中进行即可完成任务。
程序代码:
#include
#include
using namespace std; int a[1000]; int main() { int n,i; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a,a+n); int count=0; for(i=1;i<=n;i++) if(a[i]==1) { count=1; break; } if(count==0) printf("1\n"); else printf("-1\n"); return 0; }

转载于:https://www.cnblogs.com/chenchunhui/p/4678566.html

你可能感兴趣的文章
集合相关概念
查看>>
Memcache 统计分析!
查看>>
(Python第四天)字符串
查看>>
个人介绍
查看>>
使用python动态特性时,让pycharm自动补全
查看>>
关于R软件的安装
查看>>
MySQL数据库免安装版配置
查看>>
你必知必会的SQL面试题
查看>>
html5 Canvas绘制时钟以及绘制运动的圆
查看>>
Unity3D热更新之LuaFramework篇[05]--Lua脚本调用c#以及如何在Lua中使用Dotween
查看>>
JavaScript空判断
查看>>
洛谷 P1439 【模板】最长公共子序列(DP,LIS?)
查看>>
python timeit
查看>>
Wireless Network 并查集
查看>>
51nod 1019 逆序数
查看>>
JCEF3——谷歌浏览器内核Java版实现(一):使用jawt获取窗体句柄
查看>>
Java性能总结四(转)
查看>>
net 程序员面试宝典
查看>>
2019年机器学习:追踪人工智能发展之路
查看>>
2.Android新版开发教程&笔记—Activity间的数据传递
查看>>