codeforces Nuts
2015-11-06 19:24
375 查看
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
Input
3 10 3 3
Output
2
Input
3 10 1 3
Output
3
Input
100 100 1 1000
Output
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个隔板,x个隔板可以将箱子分成(x+1)个部分每一部分最多装v个坚果,求将这些坚果全部装进箱子里,最少用几个箱子?
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
Input
3 10 3 3
Output
2
Input
3 10 1 3
Output
3
Input
100 100 1 1000
Output
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个隔板,x个隔板可以将箱子分成(x+1)个部分每一部分最多装v个坚果,求将这些坚果全部装进箱子里,最少用几个箱子?
[code]#include <iostream> #include <cmath> using namespace std; int main() { int k,a,b,v; cin>>k>>a>>b>>v; int s,flag=0; if(k<b+1) s=k*v; if(k>=b+1) { s=(b+1)*v; flag=1; } if(s>=a) cout<<"1"<<endl; else { if(flag==1) { int p=ceil(1.0*(a-s)/v)+1; cout<<p<<endl; } if(flag==0) { b=b-k+1; int p=s,num=1; while(b>=k-1&&s<a) { b-=k-1; s+=p; num++; } if(s>=a) { cout<<num<<endl; } else { s+=(b+1)*v; if(s>=a) cout<<num+1<<endl; else { num+=ceil(1.0*(a-s)/v)+1; cout<<num<<endl; } } } } return 0; }
相关文章推荐
- js播放wav格式的录音文件
- html- Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用?
- 达内学习日志Day47:注册与登录(一)
- 输入框的自动提示功能
- codeforces 593B(思路)
- 100 Same Tree
- 苹果与WINDOWS 远程 工具 推荐 - teamviewer
- SharedPreferences
- 如何使用socket进行java网络编程(三)
- 在AndroidStudio中使用GreenDAO
- [Python] Numpy学习笔记(一)
- 受控访问
- 利用opencv的detector检测并保存截取的人脸图像
- Gbase数据库备份与还原
- 阅读学术论文的心得体会
- 我想要一个不同的未来
- 计算器软件的典型用户和场景
- 【小松教你手游开发】【面试必读(编程基础)】堆和栈的区别
- leetcode122 Best Time to Buy and Sell Stock II
- HDU 4504 DP