HDU 2019 Multi-University Training Contest 7 杭电2019多校联合训练赛 第七场 1006 Final Exam (6651)

HDU 2019 Multi-University Training Contest 7 杭电2019多校联合训练赛 第七场 1006 Final Exam (6651)


先膜拜一下牛大佬。
skr~


Problem Description

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 m 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 0 points, or all m points. Points must be integers; a problem cannot have 0.5 point.
What he knows, is that, these n problems will be about n 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 x points in tomorrow’s exam, it takes at least x+1 hours to prepare everything you need for examination. If he spends less than x+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 k 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 t (1≤t≤20 000), denoting the number of test cases.
Each test case are three space-separated integers n,m,k (0≤m≤109, 1≤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

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道题,总分m分,每题分值未知。QQ要去复习考试,对于一题分值为s的题,他需要复习的时间是s+1,现在QQ至少要对k题,问QQ最短的复习时间

思路

考虑最坏的打算。假设QQ能做出k-1题,那么如果复习时间最少的n-k+1题都做不出来,那么QQ就不能通过考试,那么我们考虑让QQ复习这n-k+1道题的总时间大于m,保证他至少能做出一题。之后我们需要考虑剩下的k-1题,我们应该让QQ把这些题全部做出来,所以剩下的k-1题的每题的复习时间应不少于n-k+1中最小的最大时间,即ceil((m+1)/(n-k+1))。

坑点

想不到


代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int T;
    scanf("%lld",&T);
    while(T--)
    {
        ll n,m,k;
        scanf("%lld%lld%lld",&n,&m,&k);
        printf("%lld\n",(k-1)*(ll)ceil(1.0*(m+1)/(n-k+1))+1+m);
    }
    return 0;
}

这个代码看着是不是像忽悠人。。。

发布了42 篇原创文章 · 获赞 6 · 访问量 4030

猜你喜欢

转载自blog.csdn.net/qq_43383246/article/details/99328141