hdu 5933 ArcSoft's Office Rearrangement
来源:互联网 发布:c语言的延时函数 编辑:程序博客网 时间:2024/06/01 07:30
ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company.
There areN working blocks in ArcSoft company, which form a straight line. The CEO of ArcSoft thinks that every block should have equal number of employees, so he wants to re-arrange the current blocks into K new blocks by the following two operations:
- merge two neighbor blocks into a new block, and the new block's size is the sum of two old blocks'.
- split one block into two new blocks, and you can assign the size of each block, but the sum should be equal to the old block.
Now the CEO wants to know the minimum operations to re-arrange current blocks intoK block with equal size, please help him.
There are
- merge two neighbor blocks into a new block, and the new block's size is the sum of two old blocks'.
- split one block into two new blocks, and you can assign the size of each block, but the sum should be equal to the old block.
Now the CEO wants to know the minimum operations to re-arrange current blocks into
Input
First line contains an integer T , which indicates the number of test cases.
Every test case begins with one line which two integersN and K , which is the number of old blocks and new blocks.
The second line containsN numbers a1 , a2 , ⋯ , aN , indicating the size of current blocks.
Limits
1≤T≤100
1≤N≤105
1≤K≤105
1≤ai≤105
Every test case begins with one line which two integers
The second line contains
Limits
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the minimum operations.
If the CEO can't re-arrangeK new blocks with equal size, y equals -1.
If the CEO can't re-arrange
Sample Input
31 3143 12 3 43 61 2 3
Sample Output
Case #1: -1Case #2: 2Case #3: 3
Source
2016年中国大学生程序设计竞赛(杭州)
模拟。
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;int main(){int T;ll sum,n,k,a[100010];scanf("%lld",&T);for(int Count=1;Count<=T;Count++){sum=0;scanf("%lld%lld",&n,&k);for(int i=0;i<n;i++){scanf("%lld",&a[i]);sum+=a[i];}if(sum%k){printf("Case #%d: -1\n",Count);continue;}ll quantity=sum/k;ll temp=0,t;ll ans=0;for(int i=0;i<n;i++){if(temp==0){if(a[i]<quantity)temp=a[i];else{t=a[i]/quantity;if(a[i]%quantity)//刚好能除开和不能除开是两种情况...... ans+=t;elseans+=t-1;temp=a[i]%quantity;}}else{if(temp+a[i]<quantity){temp=temp+a[i];ans++;}else{t=(a[i]+temp)/quantity;if((a[i]+temp)%quantity)ans+=t+1;elseans+=t;temp=(a[i]+temp)%quantity;}}}printf("Case #%d: %lld\n",Count,ans);}return 0;}
阅读全文
0 0
- hdu 5933 ArcSoft's Office Rearrangement【模拟】
- hdu 5933 ArcSoft's Office Rearrangement
- HDU-5933 ArcSoft's Office Rearrangement(思维)
- HDU 5933 ArcSoft's Office Rearrangement
- 【HDU 5933】 ArcSoft's Office Rearrangement 【贪心】
- HDU 5933 ArcSoft's Office Rearrangement
- HDU 5933 ArcSoft's Office Rearrangement (模拟)
- hdu 5933 ArcSoft's Office Rearrangement
- hdu 5933 ArcSoft's Office Rearrangement 思维
- hdu 5933 ArcSoft's Office Rearrangement
- HDU-5933-ArcSoft's Office Rearrangement
- hdu 5933 ArcSoft's Office Rearrangement
- HDU 5933 ArcSoft's Office Rearrangement 贪心
- hdu 5933 ArcSoft's Office Rearrangement
- HDU 5933 ArcSoft's Office Rearrangement(贪心)
- HDU 5933 ArcSoft's Office Rearrangement(模拟)
- HDU-5933-ArcSoft's Office Rearrangement-模拟(水)
- hdu 5933 ArcSoft's Office Rearrangement(贪心)
- 卡住:图片上传并回显
- NOIP2017赛前模拟 Game DP (2017.10.30)
- numpy中的mean()函数
- 关于立即运行函数
- 疑问,待自己解决
- hdu 5933 ArcSoft's Office Rearrangement
- 思维导图_LVM,RAID,计划任务
- Java面试中的多线程问题
- [DeeplearningAI笔记]ML strategy_1_1正交化/单一数字评估指标
- 算法数学推导
- clipboard.js使用总结
- 恐惧:中年程序员会害怕丢掉工作吗?
- hdu 4791 Alice's Print Service(二分)
- appium自动化测试实践之Androidstudio模拟器avd创建和连接