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


相关推荐

  • SpringBoot解决文件上传,返回可访问路径

    SpringBoot解决文件上传,返回可访问路径问题描述:SpringBoot项目中需要上传文件到当前服务器的磁盘(即物理地址),返回可访问的路径给前端。前端利用路径显示文件内容。开发环境:SpringBoot2.0以上、JDK1.81.在springboot中加入下面代码 @Value(“${file.uploadFolder}”) privateStringuploadFolder; @Bean MultipartConf…

    2022年5月2日
  • python字符串替换replace函数

    python字符串替换replace函数python字符串替换replace函数replace(old,new,count)old,旧字符或字符串new,新字符或字符串count,最大替换数量,从起始位置开始计数,默认替换所有注意:replace函数替换字符串,不影响原字符串示例1:默认替换所有s1=’2019.10.30’s2=s1.replace(‘.’,’-‘)s2’2019-10-30’…

    2022年6月7日
  • 分布式缓冲之memcache

    1.memcache简介memcache是danga.com的一个项目,它是一款开源的高性能的分布式内存对象缓存系统,,最早是给LiveJournal提供服务的,后来逐渐被越来越多的大型网站所采用

    2021年12月28日
  • Eclipse 添加 Tomcat Server 配置

    Eclipse 添加 Tomcat Server 配置以下步骤是将一个独立安装的(standalone)Tomcat整合到Eclipse中,方便在Eclipse发布Web工程到Tomcat服务器,启停WebServer调试程序。项目开发中不推荐使用Eclipse自带的WebServer,不便于运行调试,往往需要根据项目需求独立安装指定厂家和版本的Webserver。(项目部署参考–>Eclipse部署项目到Tomcat)…

    2022年10月25日
  • linux rpm解压命令,LINUX下各种解压命令收藏「建议收藏」

    linux rpm解压命令,LINUX下各种解压命令收藏「建议收藏」大致总结了一下linux下各种格式的压缩包的压缩、解压方法。但是部分方法我没有用到,也就不全,希望大家帮我补充,我将随时修改完善,谢谢!.tar解包:tarxvfFileName.tar打包:tarcvfFileName.tarDirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gunzipFileName.gz解压2:gzip-dFileN…

    2022年5月16日
  • 第四章 循环结构

    第四章 循环结构

    2021年9月28日

发表回复

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

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