本文主要是介绍CodeForces 402A Nuts,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Description
You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x(x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
Input
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
Output
Print a single integer — the answer to the problem.
Sample Input
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
Hint
In the first sample you can act like this:
- Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
- Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
题意:
给你四个数k,a,b,v;
k代表每个隔间最多不能超过的数目 ,a是果子个数,b是有多少隔板数量,v是一个隔板最多能装多少
现在问你,要把所有nuts放进去,最少需要多少boxes
简单的贪心,我们用这些隔板去装配boxes,看b能分成多少个k-1 份,每一个box就是k*v这么大的容量。
然后多余的b%(k-1) 个给最后一个box
其余的box都是v
然后b慢慢减
这个思路超赞的:#include<iostream>
using namespace std;
int main()
{int k,a,b,v;int num;cin>>k>>a>>b>>v;int sum=0;while(1){//cout<<a<<endl;if(a<=0){//cout<<"sd"<<endl;break;// 分完了}else{num=1;while(b>0){if(num<k){num++;b--;}elsebreak;}a-=num*v;sum++;}//cout<<num<<"sd"<<endl;}cout<<sum<<endl;return 0;
}
这篇关于CodeForces 402A Nuts的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!