杭电2019多校第七场 HDU——6651 Final Exam(思维+简单构造)

Final Exam is coming! Cuber QQ has now one night to prepare for tomorrow's exam. 

The exam will be a exam of problems sharing altogether mm points. Cuber QQ doesn't know about the exact distribution. Of course, different problems might have different points; in some extreme cases, some problems might worth 00 points, or all mm points. Points must be integers; a problem cannot have 0.50.5 point. 

What he knows, is that, these nn problems will be about nn totally different topics. For example, one could be testing your understanding of Dynamic Programming, another might be about history of China in 19th century. So he has to divide your night to prepare each of these topics separately. Also, if one problem is worth xx points in tomorrow's exam, it takes at least x+1x+1 hours to prepare everything you need for examination. If he spends less than x+1x+1 hours preparing, he shall fail at this problem. 

Cuber QQ's goal, strangely, is not to take as much points as possible, but to solve at least kk problems no matter how the examination paper looks like, to get away from his parents' scoldings. So he wonders how many hours at least he needs to achieve this goal. 

Input

The first line of the input is an integer tt (1≤t≤20 0001≤t≤20 000), denoting the number of test cases. 

Each test case are three space-separated integers n,m,kn,m,k (0≤m≤1090≤m≤109, 1≤k≤n≤1091≤k≤n≤109). 

Output

For each test case, output the number of hours Cuber QQ needs. 

Sample Input

2
1 10 1
10 109 10

Sample Output

11
1100

        
  

Hint

Cuber QQ should solve one problem in sample 1, so he at least prepares 11 hours when the problem one is 10 point. 
Cuber QQ should solve all the ten problems in sample 2, so he at least prepares 110 hours for each problem because there may be one problem is 109 point.

题意:一共有n道题,需要做对k道题,每个题有一个分数,要想做对这道题,需要准备的时间是这道题的分数加1,给出n道题的总分数m,问你做对k道题花费的最少时间,还有就是,你学了哪儿道题,出题人就会想办法阻止你,比如你学一道题1分钟,他会把这道题目的分数提高到>=1分,但是满足最后的总分数是m。

题解:换位思考,一开始相对了,但是一直错,后来看了题解,哇的一下我曹了,我是想他阻止我分数最小的n-k个,我把剩下的k个变成前面n-k个里面最大的数,然后加两个特判(m==0和n==k的情况)感觉挺对,还有特判,但是一直错,正确的应该是他阻止我分数最小的n-k+1个,然后把剩下的k-1个变成前面n-k个里面“最大的数(相等或者加一)”(正好整除,就是前面的数加1,不整除就是前面的向下取整加一,然后把多于的平均分到前面的上面就好),然后前面的数再加1(正好整除随便分到前面任意一个数,不整除可以加到前面的没有平均分到的那个位置),这样保证前面n-k+1个的总和>m,这样总时间会更小,还是自己太菜,奶奶个熊~~

上代码:

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		ll n,m,k;
		scanf("%lld%lld%lld",&n,&m,&k);
		printf("%lld\n",m+1+(m/(n-k+1)+1)*(k-1));
	}
	return 0;
} 
发布了195 篇原创文章 · 获赞 27 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/lgz0921/article/details/99319960
今日推荐