• 【63.73%】【codeforces 560A】Currency System in Geraldion


    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    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.

    Examples
    input
    5
    1 2 3 4 5
    output
    -1

    【题目链接】:http://codeforces.com/contest/560/problem/A

    【题解】

    只要有1所有数字就都能组成了。
    没1的话。。。
    那就是1呗…

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int n,x;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(n);
        rep1(i,1,n)
        {
            rei(x);
            if (x==1)
            {
                puts("-1");
                return 0;
            }
        }
        puts("1");
        return 0;
    }
  • 相关阅读:
    【洛谷P1962】斐波那契数列
    【洛谷P3390】【模板】矩阵快速幂
    【洛谷P3070】[USACO13JAN]岛游记Island Travels
    【NOIp模拟赛】antipalindrome
    【洛谷P3930】SAC E#1
    【洛谷P3928】SAC E#1
    【洛谷P3927】SAC E#1
    【NOIp模拟赛】binary
    【NOIp模拟赛】value
    【洛谷P2341】[HAOI2006]受欢迎的牛
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626850.html
Copyright © 2020-2023  润新知