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


相关推荐

  • django urls_url主要功能

    django urls_url主要功能前言为什么我们url需要命名呢?url命名的作用是什么?我们先来看一个案例案例我们先在一个Django项目中,创建2个App,前台front和后台cms,然后在各自app下创建urls.py文件

    2022年7月31日
    10
  • 海思h264解码库

    海思h264解码库海思的dll,解码h264 解码后转出yuv12dll自己百度下载 hi_h264dec.dll  hi_h264dec_w.dll 调用方法:if(H264Dec.Hi264DecAU(_decHandle,pH264Data,frameLen,0,ref_decodeFrame,0)==0) pH264Data是h264帧的句柄,frameLen…

    2022年6月28日
    75
  • CentOS:安装ssh

    CentOS:安装ssh

    2021年6月18日
    85
  • 在IIS上部署ASPNETMVC Beta网站[通俗易懂]

    在IIS上部署ASPNETMVC Beta网站[通俗易懂]在IIS上部署ASPNETMVCBeta网站在IIS上部署ASPNETMVCBeta网站,实际上和在IIS上部署其他类型的网站并没有太大的区别。个人觉得唯一比较有意思的是在配置IIS时,我们可以配置各种自定义的ISAPI扩展名(也在MVC应用配置的,通常在Global.asax中)第一步:安装MVC。当然,首先要下载MVCBeta,下载链接。安装的前提是.NETFramew

    2022年9月29日
    3
  • response 的ContentType 说明[通俗易懂]

    response 的ContentType 说明[通俗易懂]不同的ContentType会影响客户端所看到的效果.默认的ContentType为text/html也就是网页格式.代码如: 显示的为网页,而 则会显示html原代码.以下为一些常用的ContentTypeGIFimages  JPEGimages  TIFFimages  MICROS

    2022年7月19日
    35
  • mysql usegeneratedkeys_Mybatis Generator insert useGeneratedKeys keyProperty[通俗易懂]

    mysql usegeneratedkeys_Mybatis Generator insert useGeneratedKeys keyProperty[通俗易懂]Mybatis自动生成代码,需要用到mybatisGenerator,详见http://mybatis.github.io/generator/configreference/generatedKey.htmlinsert语句如果要返回自动生成的key值,一般会在insert里加入useGeneratedKeys属性,例如insertintosubtasks(SID,TID,RID,S…

    2022年6月26日
    38

发表回复

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

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