URAL 1515. Cashmaster (数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1515

Background

Once upon a time former petty bureaucrat, nowadays the Minister of Finance of the Soviet Federation, Victor Thiefton considered, that he had stolen so much money during the first half of his life, that
it will be enough for the last half also (this story is fully described in the problem "Crime and punishment"). As a result of this conclusion Victor intended to devote himself
to immortalizing of his good name in national opinion.

Being the Minister of Finance, Mr. Thiefton knew perfectly, that the most gratifying thing to the human eye was a banknote. So he decided to print his noble face on the banknotes issued by his Ministry.

But even Victor grasped, that it would be wrong to print his face on the banknotes, which had been already issued. Therefore a propitious occasion was given to Mr. Thiefton to carry out a financial
reform - to issue a banknote of some new denomination with his face on the both sides of it.

Problem

The time came to define a denomination of the new banknote, i.e. a positive integer, which should be printed on it. For a start, Victor took all the banknotes of different denominations, which had been
already issued till that moment, and put them in ascending order. It appeared, that there were exactly N such banknotes, and a denomination of each of them was Di dollars.
It seemed he might take any of still unused denomination. But ambitious Mr. Thiefton did not want the new banknote‘s denomination to be presented as a sum of the denominations of the banknotes, which are already issued...

And here Victor realized, that he had nearly failed to bear one extremely important thing in mind. The point was that the planned emission (i.e. an issue of a new batch of money) would inevitably cause
inflation growth, which, in its turn, might lead to a devaluation of Mr. Thiefton capital, that was plundered with such a great effort. Therefore the desired denomination should be minimized.

Input

The first line contains the integer number N (1 ≤ N ≤ 100). The second line contains N integer numbers Di (1
≤ Di ≤ 106; Di < Di+1).

Output

You should output the desired denomination of the new banknote.

Sample

input output
5
1 2 4 9 100
8

Notes

In the sample, the denominations 3, 5, 6 and 7 may be presented as sums of the denominations of the banknotes, which are already issued (3 = 1 + 2, 5 = 1 + 4, 6 = 2 + 4, 7 = 1 + 2 + 4), whereas the
denomination 8 can not be present as such sum.

题意:

求给出的数字不能组成的最小的数字,每个数字在组成另一个数字时只能用一次!

代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000007];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a, a+n);
        if(a[0] > 1)
        {
            printf("1\n");
        }
        else if(a[0] > 2)
        {
            printf("2\n");
        }
        else
        {
            int ans = 0;
            for(int i = 0; i < n; i++)
            {
                if(a[i] > ans+1)
                {
                    break;
                }
                ans+=a[i];
                //printf("ans::%d\n",ans);
            }
            printf("%d\n",ans+1);
        }
    }
    return 0;
}

时间: 2024-11-05 12:29:19

URAL 1515. Cashmaster (数学啊 )的相关文章

URAL 1727. Znaika&amp;#39;s Magic Numbers(数学 vector)

主题链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: 0.5 second Memory limit: 64 MB Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set

URAL 1727. Znaika&#39;s Magic Numbers(数学 vector)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: 0.5 second Memory limit: 64 MB Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set

URAL 2005. Taxi for Programmers (最短路 数学啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2005 2005. Taxi for Programmers Time limit: 0.5 second Memory limit: 64 MB The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their trai

URAL 2003. Simple Magic(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2003 2003. Simple Magic Time limit: 1.0 second Memory limit: 64 MB Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is enough to conjure wonderful garden

URAL 1572. Yekaterinozavodsk Great Well(数学啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1572 About a month ago two teams of the Ural State University returned from the Yekaterinozavodsk training camp. This northern city impressed them so much that they decided to return there by any mean

URAL 1820. Ural Steaks(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1820 1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant "Ural Steaks" and ordered n specialty st

ural 2029 Towers of Hanoi Strike Back (数学找规律)

ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺塔问题,给定一串只有(A, B, C)的字符串(A代表在第一根柱子,B代表在第二根柱子,C代表在第三根柱子),从前往后代表盘子的大小,第 i 个字母代表di i 个盘子在某个柱子上.问移动给定字母状态的盘子最少需要多少步. 思路:首先,从后往前看(最大的盘子),如果不在当前柱子上,那么移动到目标柱子需要 2

ural 2032 Conspiracy Theory and Rebranding (数学水题)

ural 2032  Conspiracy Theory and Rebranding 链接:http://acm.timus.ru/problem.aspx?space=1&num=2032 题意:给定一个三角形的三条边 (a, b, c),问是否可放在二维坐标,使得3个顶点都是整数点.若可以,输出任意一组解,否则,输出 -1. 思路:暴力枚举:以 a 为半径做第一象限的 1/4 圆, 以 b 为半径做 一.四 象限的半圆,存储整数点的解,暴力枚举 a 整数点与 b 整数点是否构成长度为 c

URAL 1617. Flat Spots(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1612 1617. Flat Spots Time limit: 0.5 second Memory limit: 64 MB Yekaterinburg has an extensive network of tram routes. Trams of more than ten routes go along some streets. It is clear that rails wear