2019 Multi-University Training Contest 7 HDU - 6651 Final Exam (構造)

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 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
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分,每做對一道題目就要對應的付出一定的複習時間,每道題目可以是m分,也可以是0分,反正這n道題目的總分是等於m的,比如改題目是x分,那麼就需要付出x+1分鐘複習,要不然過不了;
然後老師就會想辦法不讓你過,問做對k道題目,最少需要多少時間呢??

分析:
老師想不讓你過,那肯定是針對你花費時間最少的n-k+1道題目,這樣的話你就才做對k-1道題目,因此,這n-k+1道題目你必須付出m+1分鐘纔可以;
到現在還不能保證你能夠過,因爲剩下的k-1道題目你要付出多少時間呢??
剩下的k-1道題目就是你n-k+1道題目裏面分值最大的題目了。爲啥?
老師不是想針對你n-k+1道題目嘛,那他肯定是針對你在這n-k+1道題目裏面用時最少的,這樣你就過不了了,因此你只需在剩下的k-1道題目中用n-k+1道題目中用時最多的就好了(有人可能會問,那不就是m分嗎,但是這裏的m分我們一開始就處理了,就是那個m+1呀,,,因此剩下最大的時間即使均分的值了)

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
const int N=1e5+10;
const int INF=0x3f3f3f3f;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
    int T;
    scanf("%d",&T);
    while(T--){
        ll n,m,k;
        scanf("%lld%lld%lld",&n,&m,&k);
        ll ans=m+1;
        ans+=(ll)ceil(1.0*(m+1)/(n-k+1))*(k-1);
        printf("%lld\n",ans);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章