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
her the money but didn't say how many tickets she wanted to buy. Could Aunt Frosya determine it knowing only the 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 price of 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 that there 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
|
这是一道考人是否聪明的题目,没有现成的算法。
所以需要模拟人计算的过程,用计算机的程序思维去思考。
过程这样的:
1 先算出总钱数能购买多少张票
2 总钱数减去一张最小面值的钱,然后模票价,然后加上最小面值的钱,在减去一张票价,最后就得到灵活度的钱
3 灵活度的钱除以票价,就得到灵活度了,灵活度的钱除以票价得到零,那么就只有一种可能了,得到1就有两种可能
难以理解的话,就细心想想人是如何计算的就可以解决了。
#include <iostream>
using namespace std;
static const int AmusePartRoubles[6] = {10, 50, 100, 500, 1000, 5000};
void AmusementPark1796()
{
int A[6] = {0};
int money = 0;
for (int i = 0; i < 6; i++)
{
cin>>A[i];
money += A[i] * AmusePartRoubles[i];
}
int ticket = 0;
cin>>ticket;
int total = money / ticket;
int i = 0;
for ( ; i < 6 && A[i] == 0; i++);
int leftMoney = (money - AmusePartRoubles[i]) % ticket;
leftMoney += AmusePartRoubles[i] - ticket;
int flex = leftMoney / ticket;
cout<<flex+1<<endl;
for (int j = flex; j >= 0 ; j--)
{
cout<<total - j<<' ';
}
}
int main()
{
AmusementPark1796();
return 0;
}
分享到:
相关推荐
Unit 9 Have you ever been to an amusement park练习题及答案2.doc
八年级英语下册 Unit 9 Have you ever been to an amusement park单元综合测试 人教新目标版
unity模型资源,一个卡通类型的游乐园,内有海盗船、过山车、城堡、旋转木马等等一系列游乐设施。 风格是偏卡通类型的但又不是Q版。 已经打包为unitypackage,直接导入unity项目中即可使用。
八年级英语答案参考: ... amusement 68. were 69.of 70. probably 71. different 72. other 73. but 74. eating 75. gifts 六. 任务型阅读理解: 76. Astronauts on board the Shenzhou-10 spacecraft. 77.300
湖北省十堰市竹山县茂华中学八年级英语下册《Unit 9 Have you ever been to an amusement park》测试题 人教新目标版
河南省南乐县张果屯乡中学八年级英语下册 Unit 9《Have you ever been to an amusement park》Period学案1 人教新目标版
河南省南乐县张果屯乡中学八年级英语下册 Unit 9《Have you ever been to an amusement park》Period学案3 人教新目标版
河南省南乐县张果屯乡中学八年级英语下册 Unit 9《Have you ever been to an amusement park》Period学案2 人教新目标版
陕西省榆林市定边县安边中学八年级英语下册 Unit 9 Have you ever been to an amusement park Period 8导学案(无答案) 人教新目标版
who’s coming to the company picnic, and which amusement park has the best deal on Laser Tag so you can throw a party for your top 50 performers. You won’t have to learn to think like a programmer ...
angular-seed — AngularJS应用程序的种子该项目是典型 Web应用程序的应用程序框架。 您可以使用它快速引导您的角度化webapp项目以及这些项目的开发环境。 种子包含一个示例AngularJS应用程序,并且已预先配置为安装...
拉尔斯游乐园目标熟悉使用表单助手,使模型彼此交互以及构建简单的会话系统的习惯。 您将要建造一个游乐园。 将会有用户,景点,并且用户可以乘坐景点。指示建设这个游乐园将需要结合过去几个单元中引入的许多想法。...
湖北省武汉市北大附中武汉为明实验中学八年级英语下册 Unit 9 Have you ever been to an amusement park?基础练习(B卷) 人教新目标版