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


相关推荐

  • Mysql+DRBD+Heartbeat 实现mysql高可用的双击热备(DRBD篇)

    Mysql+DRBD+Heartbeat 实现mysql高可用的双击热备(DRBD篇)

    2021年8月30日
    45
  • oracle手动 建库_Oracle手动建库过程

    oracle手动 建库_Oracle手动建库过程最近在网上看到很多初学 Oracle 或是从旧版的 Oracle 升级到 10G 的朋友们都问如何在 Oracle10G 里手工建库的问题 今天正好有空 于是乎把在 Oracle10G 里手工建库的全过程写出来 供各位从事 Oracle 工作和学习的同朋友们参考 希望能够对大家有所帮助 在 Oracle 中建库 通常有两种方法 一是使用 Oracle 的建库工且 DBCA 这是一个图形界面工且 使用起来方便且很容易理解 因为它

    2025年6月13日
    1
  • jsonObject [通俗易懂]

    jsonObject [通俗易懂]JSON就是一串字符串只不过元素会使用特定的符号标注。{"age":14;"name":“lisi”}这就是一个对象了json数组含有多个json对

    2022年7月4日
    24
  • leetcode 三数之和_leetcode数组交集

    leetcode 三数之和_leetcode数组交集原题链接给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。注意:答案中不可以包含重复的三元组。示例 1:输入:nums = [-1,0,1,2,-1,-4]输出:[[-1,-1,2],[-1,0,1]]示例 2:输入:nums = []输出:[]示例 3:输入:nums = [0]输出:[] 提示:0 <= nums.length <= 300

    2022年8月8日
    6
  • js 字符串截取指定字符

    js 字符串截取指定字符letstr=’helloworld’//如截取hello//indexOf,查找字符串,有返回下标,没有返回-1letindex=str.indexOf(‘hello’)//substring,参数是从哪截取到哪,不接受负数letcutOut1=str.substring(index,index+5)/…

    2022年4月29日
    68
  • Silverlight ASP.NET control

    Silverlight ASP.NET control

    2021年7月24日
    58

发表回复

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

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