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", n);
    for(set<int>::iterator it = ans.begin(); it != ans.end(); it ++) printf("%s%d", it != ans.begin() ? " " : "", *it);
    return 0;
}
时间: 2024-08-28 13:22:40

URAL 1796. Amusement Park (math)的相关文章

URAL - 1796 Amusement Park(水)

Amusement Park Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description 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

URAL 2025. Line Fighting (math)

2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment

URAL 1073 Square Country(DP)

题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 :其实就是求x12+x22+--+Xn2中的最小的n. 1 //1073 2 #include <stdio.h> 3 #include <iostream> 4 #include <math.h> 5 6 using namespace std ; 7 8 int a[

URAL 1167. Bicolored Horses (DP)

题目链接 题意 :农夫每天都会放马出去,然后晚上把马赶入马厩,于是让马排成一行入马厩,但是不想马走更多的路,所以让前p1匹入第一个马厩,p2匹马入第二个马厩…………但是他不想让他的任何一个马厩空着,所有的马都必须入马厩.有两种颜色的马,如果 i 匹黑马与 j 匹白马同在一个马厩,不愉快系数是 i * j,总系数就是k个系数相加.让总系数最小. 思路 : dp[i][j] 代表的是前 i 个马厩放 j 匹马的最小不愉快系数值. 1 //1167 2 #include <cstdio> 3 #in

URAL 1306 Sequence Median(优先队列)

题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶数)或第(n+1)/2大(n为奇数).所以可以用优先队列来维护最值,这样只需要存一半元素(n/2+1个元素)就可以了. #include<cstdio> #include<algorithm> #include<queue> #define UL unsigned int

Ural 1780 Gray Code (暴力)

Ural 1780 题意: 输入一个二进制数与该二进制数的格雷码,但有一些位置不确定,写程序将其恢复,无法恢复输出Impossible,多解输出Ambiguity. 思路: 其实是个普通的乱搞题.. Gray码的定义:Gi=Bi?1?Bi,G0=B0 (第i位格雷码等于第i位二进制码与第i-1位二进制码的异或值) 然后按照这个定义编码,正向反向各自编一遍,出现矛盾输出Impossible,最后还含有'?'则有多解. 代码: /* * @author FreeWifi_novicer * lang

Ural 1146 Maximum Sum(DP)

题目地址:Ural 1146 这题是求最大子矩阵和.方法是将二维转化一维. 首先用n*n的方法来确定矩阵的列.需要先进行预处理,只对每行来说,转化成一维的前缀和,这样对列的确定只需要前后两个指针来确定,只需要用前缀和相减即可得到.前后两个指针用n*n的枚举. 确定好了哪几列,那么再确定行的时候就转化成了一维的最大连续子序列的和.再来一次O(n)的枚举就可以. 这样,总复杂就变成了O(n^3),对于n为100来说,已经足够了. 代码如下: #include <iostream> #include

Ural 2018The Debut Album(DP)

题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #i

Ural 1303 Minimal Coverage(贪心)

题目地址:Ural 1303 先按每个线段的左端点排序,然后设置一个起点s,每次都从起点小于等于s的线段中找到一个右端点最大的.并将该右端点作为新的起点s,然后继续找.从左到右扫描一遍即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #inc