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

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

  1. URAL 2025. Line Fighting (math)

    2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...

  2. 组合数学(math)

    组合数学(math) 题目描述 为了提高智商,zjy开始学习组合数学.某一天她解决了这样一个问题:“给一个网格图,其中某些格子有财宝.每次从左上角出发,只能往右或下走.问至少要走几次才能把财宝全部捡完 ...

  3. URAL 1069 Prufer Code(模拟)

    Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...

  4. Timus 1796. Amusement Park 聪明题

    On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt Frosy ...

  5. URAL 1741 Communication Fiend(最短路径)

    Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...

  6. URAL 1139 City Blocks(数论)

    The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...

  7. js 算數(Math)對象

    算數對象不需要聲明,可以直接使用, Math對象方法及作用: round()四捨五入: random()生成0到1的隨機數: max()選擇較大的數: min()返回較小的數:

  8. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  9. URAL 1306 Sequence Median(优先队列)

    题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...

随机推荐

  1. try/catch异常捕捉

    StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); System.out.println(sw. ...

  2. SpringBoot优化内嵌的Tomcat

    SpringBoot测试版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId ...

  3. java 科学计数法表示转换

    BigDecimal strScien = new BigDecimal("9.67953970412123E-05"); System.out.println(strScien. ...

  4. ios ViewController present不同的方向

    First ViewController CATransition *transition = [CATransition animation]; transition.duration = 0.3; ...

  5. HtmlTextWriter学习笔记

    本文来自:http://www.cnblogs.com/tonyqus/archive/2005/02/15/104576.html 这两天正好在研究asp.net自定义控件制作,HtmlTextWr ...

  6. Android项目 手机安全卫士(代码最全,注释最详细)之十二 设置中心的界面

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...

  7. 【字母树+贪心】【HDU3460】【Ancient Printer】

    题目大意: 一个打印机 只有 打印,删除,a-z.操作 给你一堆队名,如何才能操作次数最少输出全部 (字典树节点数-1)*2 输入,删除操作数 字符串数 printf操作数 最长字符串的长度 最后一个 ...

  8. 【二进制拆分多重背包】【HDU1059】【Dividing】

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. 小心ThreadLocal的陷阱

    ThreadLocal用在多线程时保存线程级的局部变量,当我们需要在线程内共享数据时,ThreadLocal屡试不爽,但是ThreadLocal也会有一个问题,当你使用线程池时,线程可能会被重用,所以 ...

  10. 读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit

    读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit Author: Andrew Hunt ,David Thomas with Matt ...