Timus 1796. Amusement Park 聪明题[通俗易懂]

Timus 1796. Amusement Park 聪明题

大家好,又见面了,我是全栈君。

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115766.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月30日 下午10:00
下一篇 2022年1月30日 下午11:00


相关推荐

  • linux 安装tinyxml,使用TinyXml「建议收藏」

    linux 安装tinyxml,使用TinyXml「建议收藏」使用TinyXml的两种方法。第一,导入所需的头文件和cpp文件TinyXml由两个头文件(.h文件)和四个CPP文件(.cpp文件)构成,用的时候,只要将(tinyxml.h、tinystr.h、tinystr.cpp、tinyxml.cpp、tinyxmlerror.cpp、tinyxmlparser.cpp)导入工程就可以用它的东西了。这就是开源的好处,就跟你自己写的程序一样,想怎么用都行。…

    2022年6月11日
    233
  • latex缩进与对齐_latex 换行后缩进「建议收藏」

    latex缩进与对齐_latex 换行后缩进「建议收藏」且每个条目输入完毕之后不需要做任何的强迫换行记号,如:\\\\(换行符)或者\\par(分段符)Latex可以自动处理四重enumerate嵌套,编号规则为第一级自然数,第二级……那么,如何让空格在本行行尾自动换行?有两种方法可以实现:方法一:选中文字,然后点击格式——段落——缩进和间距,在常规栏中,选择对齐方式为“左对齐”……且每个条目输入完毕之后不需要…

    2022年5月15日
    359
  • 小米手环app android,小米健康官方app[通俗易懂]

    小米健康官方app是一款基于手机传感器实现的,提供健康监测、分析、服务的应用https://woshiluren.lanzous.com/b00zcdbtg。保持每天随身携带手机,它就能分析你一天健康状态,并依据你的个人基础信息,自动定制健康目标,给予健康提示。目前只提供运动和睡眠相关的服务,后续我们还将推出更多维度的健康服务。应用特色目前只提供运动和睡眠相关的服务。保持每天随身携带手机,它就能分…

    2022年4月9日
    78
  • PAT乙级——1003

    PAT乙级——1003题目:我要通过!(20分)“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送——只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。得到“答案正确”的条件是:字符串中必须仅有P、A、T这三种字符,不可以包含其它字符;任意形如xPATx的字符串都可以获得“答案正确”,其中x或者是空字符串,或者是仅由字母A…

    2022年5月22日
    34
  • 复数集合作为数域C和数域R上的空间

    复数集合作为数域C和数域R上的空间经常有同学问复数集合作为复数域和实数域上的线性空间的区别 本文给予一个比较详细的解释 1 线性空间定义的四个要素线性空间 V V cdot V 是一个代数系统 它的定义有四个要素 1 一个数域 PPP 2 一个非空集合 VVV 3 两种线性运算 加法和数乘 4 八条运算规律 加法运算律 A1 A4A 1 simA 4A1 A4 数乘运算律 M1 M4M

    2026年3月17日
    1
  • 从安装到自我进化:OpenClaw 完整使用指南

    从安装到自我进化:OpenClaw 完整使用指南

    2026年3月13日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号