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;
    }
  • 相关阅读:
    TO DO List
    springboot 热部署
    <dependencyManagement>的作用
    人体工程学座椅
    temp
    temp
    声明式编程和命令式编程的本质区别
    weak first question
    Spring依赖注入方式和依赖来源
    SpringBoot 整合 H2 数据库
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4678566.html
Copyright © 2011-2022 走看看