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;
        }
  • 相关阅读:
    在linux系统安装tomcat后,bin文件下startup.sh启动不
    利用教育邮箱注册JetBrains产品(pycharm、idea等)的方法
    linux 查看当前系统版本号
    windows 重装系统
    linux rpm方式安装mysql
    官网下载MySQL最新版本的安装包
    Redis随笔
    八大排序算法的java实现
    XML的两种解析方式
    Quartz快速入门
  • 原文地址:https://www.cnblogs.com/yilihua/p/4674622.html
Copyright © 2011-2022 走看看