hdu 5933
来源:互联网 发布:端口名称怎么查 编辑:程序博客网 时间:2024/06/05 16:13
注意细节
从左向右,贪心
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){int t,cnt=0;scanf("%d",&t);while(t--){int n,k;scanf("%d%d",&n,&k);int a[100005];long long sum=0;long long ans=0;for(int i=0;i<n;i++){scanf("%d",&a[i]);sum+=a[i];}if(sum%k!=0) {printf("Case #%d: -1\n",++cnt); continue;} long long temp=sum/k;sum=a[0];if(a[0]>=temp){int t=a[0]/temp;if(a[0]%temp==0) t--;sum-=(a[0]/temp)*temp;ans+=t;}for(int i=1;i<n;i++){if(sum!=0) ans++;sum+=a[i]; if(sum>=temp){int t=sum/temp;if(sum%temp==0) t--;sum-=(sum/temp)*temp;ans+=t;}}printf("Case #%d: %I64d\n",++cnt,ans);} }
阅读全文
0 0
- hdu 5933
- hdu-5933
- HDU 5933
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- SSL2687 2017年8月14日提高组T1 跳跃(kruskal,并查集)
- MongoDB:分片的配置
- NYOJ5平台最优程序
- Number Sequence
- 关于Fragment中getActivity为Null的问题
- hdu 5933
- 暑假集训第十五天
- angular学习总结二——数据&事件绑定(ngIf、ngFor、ngSwitch、ngModel)
- Java 多catch
- java 16进制字符串 转 byte[] 转文件 文件 转byte[] 转16进制字符串
- VS10打开VS12版本创建的工程
- poj 3261 (后缀数组+二分)
- 二分练习
- C语言中的宏定义