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;
    }
  • 相关阅读:
    函数式编程
    javascript RegExp类型 学习小记
    javascript Date类型 学习笔记
    post 提交数据
    git学习笔记
    Winform DevExpress控件库(一) 使用SplashScreenManager控件定制程序加载页面
    .net 对json数据进行读取
    [WPF]TextTrimming截断后,ToolTip显示完整信息
    删除程序自身
    c/s项目记住账号密码功能
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4678566.html
Copyright © 2011-2022 走看看