UCF Local Contest — September 5, 2015 Brownies vs. Candies vs. Cookies(模拟)

60.38% 1000ms 262144K
Everyone is welcome to the UCF Programming Team practices, and many students take advantage of this opportunity. The main benefit is that these students improve their problem solving and programming skills. Another benefit is that the students enjoy the refreshments Dr.Orooji brings every week! Dr.O usually brings candies but sometimes he brings cookies or brownies. Brownies are very popular and don’t usually last long, so Dr.O has to come up with some clever trick to make the brownies last longer (so that the students stay for the entire practice!). Well, the easiest solution is to cut the brownies in half; that will double the number of brownies.

The Problem:

Given the original number of brownies and the students wanting brownies, you are to keep track of the brownie count as Dr.O cuts them in half.

The Input:

The first input line contains a positive integer, n, indicating the number of programming team practices. This is followed by the data for these practices. The first input line for each practice contains two integers (separated by a space): the number of students (between 1 and 30 inclusive) in the practice and the number of brownies (between 60 and 600 inclusive) Dr.O has brought that day. The next input line for the practice contains a positive integer, m, indicating how many groups of students approach the refreshment table to take brownies. This is followed by the number of students in each group, one number per line. Assume that the input values are valid, e.g., the number of students in a group will be at least 1 and it will not be greater than the number of students in the practice.

If a group of students is approaching the refreshment table and Dr.O notices that the number of remaining brownies is less than or equal to the number of students in the group, Dr.O cuts the brownies in half to be sure they won’t be all gone after each student in the group grabs one brownie. Note that, if needed, Dr.O will cut the brownies more than once (as many times as needed). For example, if there are 3 brownies left and 24 students are approaching the table, Dr.O has to cut the brownies four times (3 → 6 → 12 → 24 → 48) to be sure the brownies won’t be all gone after each student in the group grabs one.

The Output:

At the beginning of each practice, output “Practice #p: s b” where p is the practice number (starting with 1), s is the number of students in this practice, and b is the number of brownies. Then, on each of the following output lines, print the number of students in a group approaching the refreshment table and the number of brownies left after each of these students has grabbed one brownie (note that cutting in halves may occur before grabbing). Leave a blank line after the output for each practice.

样例输入复制
2
20 60
8
15
10
20
18
9
12
2
10
15 100
4
1
2
3
5
样例输出
Practice #1: 20 60
15 45
10 35
20 15
18 12
9 3
12 12
2 10
10 10

Practice #2: 15 100
1 99
2 97
3 94
5 89

题目链接:https://nanti.jisuanke.com/t/43388
solution:题目有点长、有点像阅读题、但是看懂之后基本上还是没有什么难度的

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i){
		int stu, bro, m, temp;
		cin >> stu >> bro >> m;
		printf("Practice #%d: %d %d\n", i + 1, stu, bro); 
		while (m--){
			cin >> temp;
			cout << temp << ' ';
			while (bro <= temp)bro <<= 1;
			bro -= temp;
			cout << bro << endl;
		}
		putchar('\n');
	}
	return 0;
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值