zoukankan      html  css  js  c++  java
  • URAL 1796. Amusement Park (math)

    1796. Amusement Park

    Time limit: 1.0 second
    Memory limit: 64 MB
    On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt Frosya,who was a very kind and quiet person, worked at the ticket window on that day. The teacher gave herthe money but didn't say how many tickets she wanted to buy. Could Aunt Frosya determine it knowing onlythe numbers of different notes the teacher gave? It is assumed that the teacher didn't give extra notes,which means that there would not be enough money for the tickets if any of the notes was taken away.

    Input

    The first line contains six nonnegative integers separated with a space; these are the numbers of 10, 50, 100,500, 1000, and 5000 rouble notes the teacher gave to Aunt Frosya. In the second line you are given the priceof one ticket; it is a positive integer. All the integers in the input data do not exceed 1000.

    Output

    Find the number of tickets the teacher wanted to buy. Output the number of possible answers in the first line.The variants in ascending order separated with a space must be given in the second line. It is guaranteed thatthere is at least one variant of the answer.

    Samples

    input output
    0 2 0 0 0 0
    10
    
    5
    6 7 8 9 10
    
    1 2 0 0 0 0
    10
    
    1
    11
    Problem Author: Eugene Kurpilyansky, prepared by Egor Shchelkonogov
    Problem Source: Ural Regional School Programming Contest 2010




    解析:the teacher didn't give extra notes,which means that there would not be enough money for the tickets if any of the notes was taken away.这句是关键。依照这个原则,我们确定能够买票的最小和最大钱数。然后按顺序求出能买的票数。




    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int b[6] = {10, 50, 100, 500, 1000, 5000};
    set<int> ans;
    
    int main(){
        #ifdef sxk
            freopen("in.txt", "r", stdin);
        #endif // sxk
    
        int a[6], k, sum = 0;
        int t = 0;
        for(int i=0; i<6; i++){
            scanf("%d", &a[i]);
            sum += a[i] * b[i];
            if(!t && a[i]) t = b[i];
        }
        scanf("%d", &k);
        for(int i=sum - t + 1; i <= sum; i++){
            if(i % k == 0) ans.insert(i / k);
        }
        int n = ans.size();
        printf("%d
    ", n);
        for(set<int>::iterator it = ans.begin(); it != ans.end(); it ++) printf("%s%d", it != ans.begin() ? " " : "", *it);
        return 0;
    }
    


  • 相关阅读:
    福建省队集训被虐记——DAY1
    bzoj1755 [Usaco2005 qua]Bank Interest
    bzoj1754 [Usaco2005 qua]Bull Math
    bzoj1753 [Usaco2005 qua]Who's in the Middle
    wikioi1369 xth 砍树
    wikioi1191 数轴染色
    bzoj1189 [HNOI2007]紧急疏散evacuate
    POJ 3734 Blocks(矩阵快速幂+矩阵递推式)
    斐波那契+大数相加
    矩阵的快速幂
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5210968.html
Copyright © 2011-2022 走看看