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


相关推荐

  • 我的世界java手机_我的世界java手机版

    我的世界java手机_我的世界java手机版我的世界java手机版是一款非常好玩的模拟经营游戏,游戏非常的自由,你几乎可以在游戏中干任何事,你可以自己建造一个世界,或是制作一个像素版的动漫人物,你还可以探索这个世界,寻找资源,你还可以和好友一起在这里进行对抗,你还在等什么,赶快来体验吧!我的世界java手机版游戏特色没有华丽的画面,没有什么游戏特效但是它最大的优势就是在于它的游戏性玩家在一个完全开放的世界,可以完全按照自己的想法建造我的世界…

    2022年7月8日
    20
  • Text Justification — LeetCode

    Text Justification — LeetCode

    2022年1月7日
    37
  • spring boot拦截器和过滤器_java拦截器的作用

    spring boot拦截器和过滤器_java拦截器的作用SpringMVC中有两种很普遍的AOP实现:1.过滤器(Filter)2.拦截器(Interceptor)首先说一下两者之间的区别:过滤器和拦截器非常相似,但是它们有很大的区别a.最简单明了的区别就是过滤器可以修改request,而拦截器不能b.过滤器需要在servlet容器中实现,拦截器可以适用于javaEE,javaSE等各种环境c.拦截器可以调用IOC容器中的各种依赖,而过滤器不能d.过滤器只能在请求的前后使用,而拦截器可以详细到每个方法一、HandlerInterc

    2022年8月23日
    6
  • 交换机基础

    交换机基础

    2022年2月2日
    81
  • react router 路由守卫_React路由鉴权的实现方法「建议收藏」

    react router 路由守卫_React路由鉴权的实现方法「建议收藏」前言上一篇文章中有同学提到路由鉴权,由于时间关系没有写,本文将针对这一特性对vue和react做专门说明,希望同学看了以后能够受益匪浅,对你的项目能够有所帮助,本文借鉴了很多大佬的文章篇幅也是比较长的。背景单独项目中是希望根据登录人来看下这个人是不是有权限进入当前页面。虽然服务端做了进行接口的权限,但是每一个路由加载的时候都要去请求这个接口太浪费了。有时候是通过SESSIONID来校验登陆…

    2022年6月8日
    131
  • 云服务器和云虚拟主机的区别、利弊[通俗易懂]

    云服务器和云虚拟主机的区别、利弊[通俗易懂]虚拟主机虚拟主机是利用云技术把一台服务器划分为多个的“虚拟的主机”,划分出来的虚拟主机具有独立域名(能够独立的搭建网站)和完整的Internet服务器的功能,但是带宽和IP是共享服务器的。优势:由于是分享的服务器带宽、IP等所有在价格上分成便宜。虚拟主机一般都是配置好环境的用户能直接使用,客户在购买使用上非常方便。劣势:由于带宽时共享的,虚拟主机的带宽上是没有保障的。IP共享那么安全性…

    2022年6月25日
    27

发表回复

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

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