codeforces Round #236(DIV 2)A. Nuts

来源:互联网 发布:js div onclick事件 编辑:程序博客网 时间:2024/04/30 17:39

A. Nuts
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ksections. 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 kabv (2 ≤ k ≤ 10001 ≤ 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 test(s)
input
3 10 3 3
output
2
input
3 10 1 3
output
3
input
100 100 1 1000
output
1
Note

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个隔板,x个隔板可以将箱子分成(x+1)个部分每一部分最多装v个坚果,求将这些坚果全部装进箱子里,最少用几个箱子?


#include <iostream>#include <math.h>using namespace std;int main(){    int k,a,b,v;    int ans=0;    cin>>k>>a>>b>>v;    while (a>0)    {        if(b+1<=k)    //隔板能分割的部分小于k,则一次性把隔板用完        {            ans++;            a-=(b+1)*v;            b=0;            if(a>0)   //隔板用完了            {                ans+=ceil(a*1.0/v);                a=0;            }        }        else       // //隔板能分割的部分大于k,则用掉k-1个隔板        {            ans++;            a-=k*v;            b-=k-1;        }    }    cout<<ans<<endl;    return 0;}

0 0
原创粉丝点击