cf——236——A. Nuts
来源:互联网 发布:乐高 机器人 编程 编辑:程序博客网 时间:2024/05/21 08:38
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.
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.
Print a single integer — the answer to the problem.
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
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.
#include<iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;int main(){ int k,a,b,v; while(cin>>k>>a>>b>>v) { int count=0; if(a%v==0) count=a/v; else count=a/v+1; if(k==1) cout<<count<<endl; if(k>=count&&b>=count-1) cout<<"1"<<endl; else { int sum=0,s=0,ok=1,t=0; for(int i=1;i<=b;i++) { if(ok) t++; ok=0; s++; if(i%(k-1)==0) { ok=1; sum+=k; s=0; if(sum==count) break; } if(sum+s+1==count) break; } if(s) sum+=s+1; t+=count-sum; cout<<t<<endl; } } return 0;}
- cf——236——A. Nuts
- CF 402A - Nuts
- cf——#30A
- A. Nuts
- CF——#109div1 A
- CF——#104div1 A
- cf——A. Unusual Product
- cf——A. The Great Game
- cf——A. Mashmokh and Lights
- cf——A. Down the Hatch!
- 7.13——cf 304A
- Codeforces Round #236 (Div. 2) A. Nuts
- Codeforces Round #236 (Div. 2) A. Nuts
- codeforces Round #236(DIV 2)A. Nuts
- CF 7A——比赛A Kalevitch and Chess
- 《算法》第二章——Nuts and bolts(螺丝和螺帽)
- codeforce 402A - Nuts
- CodeForces 402A Nuts
- Cygwin 无法使用163源解决方法(不指向cygwin目录)
- javaweb之jstl+el完成数据迭代
- 第二周作业
- 8926平台boot过程分析
- 处理器或是微控制器的字、半字、字节的理解
- cf——236——A. Nuts
- ExtJs4 笔记(3) Ext.XTemplate 模板
- 13种APP推广手段与渠道
- Android生命周期
- JAVA_银行业务调度系统
- “都叫兽”背后的韩国文化
- 脚本之oracle 查看启动时间和运行时间
- linux负载检测命令
- 第一个Win32窗口程序