zoukankan      html  css  js  c++  java
  • 货币问题

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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 minimum unfortunate 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,如果一个数组里没有1就输出1即行。但是值得注意的就是后面的FOR循环不能写前面那For循环的变量用相同的,这样会导致AC不了。

    程序代码:

    #include<iostream>
    using namespace std;
    int a[1006];
    int main()
    {
        int n,flag=1;
        cin>>n;
    
            for(int i=0;i<n;i++)
           cin>>a[i];
            for(int k=0;k<n;k++)
            {
                if(a[k]==1)
                {
                    flag=0;
                    break;
                }
            }
            if(flag)
                cout<<"1"<<endl;
            else cout<<"-1"<<endl;
    
            return 0;
        }
  • 相关阅读:
    含字母数字的字符串排序算法,仿Windows文件名排序算法
    WCF、WPF、Silverlight和区别(转)
    线程组的介绍
    python基础字符串的修改
    c语言
    python 字典
    单元测试相关
    python列表
    如何才能设计出好的测试用例
    字符串查找
  • 原文地址:https://www.cnblogs.com/yilihua/p/4674622.html
Copyright © 2011-2022 走看看