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


相关推荐

  • 基于树莓派的舵机控制原理

    基于树莓派的舵机控制原理舵机控制原理。分为数字舵机和模拟舵机。数字舵机,又称伺服电机。舵机的控制原理舵机一般由三根线组成。灰线GND,红线电源,黄线信号线。舵机的控制,通过PWM波调制,发出控制电平,产生控制电压与舵机内的电位器作比较,获得电压差输出。最后由电压差,决定舵机转向的角度。SR-1501舵机,是一种不错的标准的机器人舵机。数字舵机的代码编程控制。一般原理:

    2022年6月22日
    84
  • js获取request中的值_set协议工作原理

    js获取request中的值_set协议工作原理设置http请求头HttpURLConnection.setRequestProperty(Stringkey,Stringvalue); 这个我居然都忘记了,哎~真是岁数大了,心好累。。。 例如:下面就是一个完整的原始网络请求方式HttpURLConnectionconn=null;try{…

    2022年9月11日
    0
  • 软件设计——UML类图详解「建议收藏」

    一:UML类图思维导图 思维导图地址:http://naotu.baidu.com/file/df1cb03489378d2a541d3d8d181399da?token=2eb1feb8006fa607 密码:33bZ二:详细分析和介绍下面就从上面的思维导图开始,详细的介绍UML类图! 在讲解之前请看关系线条图(一定要牢记): 1、 什么是UML,概念是什么? 统一建模语言

    2022年2月25日
    71
  • mt4支持python么_py-mt4

    mt4支持python么_py-mt4py-mt4用Python来写MT4的自动化交易脚本????原理使用MQL4原生库调用ZERO-MQ作为消息服务端使用其它语言,如Python作为客户端调用接口安装教程克隆代码下来关闭杀毒软件!!!解压MT4配置文件.rar把Include的东西放到MT4的Include文件夹下把Library/X86/的东西放到MT4的Library文件夹下把ZeroMQ_MT4_EA_Template_Edite…

    2022年5月8日
    45
  • jar包和war包的区别

    jar包和war包的区别1.概念1.1jar包JAR包是类的归档文件,JAR文件格式以流行的ZIP文件格式为基础。与ZIP文件不同的是,JAR文件不仅用于压缩和发布,而且还用于部署和封装库、组件和插件程序,并可被像编译器和JVM这样的工具直接使用。2.2war包war包是JavaWeb程序打的包,war包里面包括写的代码编译成的class文件,依赖的包,配置文件,所有的网站页面,包括html,jsp等等。一个war包可以理解为是一个web项目,里面是项目的所有东西。2.目录结构

    2022年5月10日
    56
  • 虚拟机桥接模式不能上网

    虚拟机桥接模式不能上网首先我的主机的有线连接是正常的,如下: 但是我的虚拟机的网络连接模式为桥接模式,但是却上不了网,如下:  我们来确认下,我的虚拟机的网络模式,如下: 设置全部都是对的,但是为什么就是不能上网呢?后来我发现,原来是虚拟网络编辑器的设置有问题,如下: 我们点击“虚拟网络编辑器”,如下: 由上图,我们可以知道,我的“桥…

    2022年4月26日
    34

发表回复

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

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