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;
    }
    


  • 相关阅读:
    存储引擎的优缺点及增删改查基本操作
    安装Mariadb
    Mysql 入门概念
    Nginx语法着色
    find用法,文件压缩和lsof和cpio
    软件包管理
    Django 生成六位随机图片验证码
    Django自定义过滤器和自定义标签
    Django零碎知识点
    jQuery实现淡入淡出样式轮播
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5210968.html
Copyright © 2011-2022 走看看