zoukankan      html  css  js  c++  java
  • 2015 HUAS Summer Contest#1~A

    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<cstdio>
    #include<algorithm>
    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
    ");
           else printf("-1
    ");
    return 0;
    }
  • 相关阅读:
    day003|python基础回顾3
    14Linux之网络管理
    13Linux之磁盘管理
    12Linux之进程管理
    11Linux之软件包管理
    10Linux之用户权限管理
    09Linux之文件管理
    08Linux之目录结构
    07Linux之bash解释器交互式环境特性
    06Linux之shell介绍
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4678566.html
Copyright © 2011-2022 走看看