前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Timus 1796. Amusement Park 聪明题[通俗易懂]

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

作者头像
全栈程序员站长
发布2022-01-31 14:33:18
2310
发布2022-01-31 14:33:18
举报

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

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就有两种可能

难以理解的话,就细心想想人是怎样计算的就能够攻克了。

代码语言:javascript
复制
#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.cn/115766.html原文链接:https://javaforall.cn

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
  • Samples
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com