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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • telnet发电子邮件

    telnet发电子邮件

    2022年1月12日
    49
  • C/C++中随机函数rand()和srand()的用法「建议收藏」

    C/C++中随机函数rand()和srand()的用法「建议收藏」一、rand()函数名:rand功能:随机数发生器用法:intrand(void);所在头文件:stdlib.h函数说明:rand()的内部实现是用线性同余法做的,它不是真的随机数,因其周期特别长,故在一定的范围里可看成是随机的。

    2022年4月29日
    42
  • Navicat premium15 激活码【2022免费激活】2022.03.10

    (Navicat premium15 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~1M2OME2TZY-eyJsaWNlb…

    2022年4月2日
    2.1K
  • post调试工具_HTTP设置

    post调试工具_HTTP设置此工具用于http调试;具有以下特点;1.支持HTTP和HTTPS(SSL加密)网络协议的跟踪和调试。2.可以查看到HTTP/HTTPS协议连接的详细过程和返回结果。3.允许GET/POST/HEAD/PUT四种连接方式。4.支持HTTP的Proxy代理。5.自动处理重定向Redirect功能。6.自动处理Cookie的接收和发送。7.可以自行设置和增加HTTP请求命令的参数。先试一下本地使用;本地IIS9001端口发布了一个网站;按下图输入;点击St…

    2022年10月9日
    4
  • 西门子SCL定时器_西门子plc断开延时定时器

    西门子SCL定时器_西门子plc断开延时定时器在西门子PLC中利用STEP7软件编程的时候,想实现延时接通功能,通常会用到S_ODT定时器,因为这个最简单。在SCL中同样可以也将这个简单的延时接通定时器使用上,只不过没有像在LAD梯形图中编程那么简单了,稍微繁复了一些,当然这只是我个人意见。还是来看一下我的做法吧,如下图:该图片是SCL建立的源文件,编译后将会生成一个FC1的程序块。图中可以看到我定义了4个输入变量,2个输出变量,以及一个临时变量。可以看到最后编译的结果是0错误0警告!…

    2022年9月26日
    4
  • Centos7中通过docker安装mysql

    Centos7中通过docker安装mysql

    2022年3月12日
    65

发表回复

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

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