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;
    }
  • 相关阅读:
    java基础 -- 经典排序
    java 基础 ----- Arrays 工具类
    java基础 ---- 二维数组
    java基础 ---- 一维数组
    java基础 ---- 练习for循环
    AI 偏微分方程
    AI 反向传播神经网络
    AI 判别式模型和生成式模型
    AI 隐含狄利克雷分布
    AI 朴素贝叶斯分类
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4678566.html
Copyright © 2011-2022 走看看