CF83B:Doctor(二分)
来源:互联网 发布:海口seo外包 编辑:程序博客网 时间:2024/05/18 13:47
题意:N只动物去看病,每只动物要看a[i]次,每只动物看完1次病且还需要继续看病就排到队列尾,医生只看K次病,问看完K次后队列的情况。
思路:二分答案,医生从第1个看到第N个动物算作1轮,二分出看完K次动物至多要多少轮,然后余数余多少就从那只动物开始排头。
# include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 1e5+30;int n, a[maxn];LL k, yu;bool check(LL x){ LL sum = 0; for(int i=0; i<n; ++i) { sum += min((LL)a[i], x); if(sum > k) return false; } return true;}int main(){ scanf("%d%I64d",&n,&k); LL sum = 0; for(int i=0; i<n; ++i) scanf("%d",&a[i]), sum += a[i]; if(k > sum) return 0*puts("-1"); LL l = 0, r = sum; while(l <= r) { LL m = l+r>>1; if(check(m)) l=m+1; else r = m-1; } sum = 0; for(int i=0; i<n; ++i) sum += min((LL)a[i], r); yu = k - sum; int st = 0, flag = 1; for(int i=0; i<n; ++i) { a[i] -= min((LL)a[i], r); if(a[i]) { if(yu == 0 && flag) { flag = 0; st = i; } else if(yu > 0) { --yu; --a[i]; } } } for(int i=st; i<n; ++i) if(a[i]) printf("%d ",i+1); for(int i=0; i<st; ++i) if(a[i]) printf("%d ",i+1); puts(""); return 0;}
阅读全文
0 0
- CF83B:Doctor(二分)
- codeforces G. Doctor(二分查找)
- Codeforces 83B Doctor(二分)
- Doctor NiGONiGO’s multi-core CPU(最小费用最大流模板)
- About doctor degree
- norton disk doctor
- The Doctor Knows Better
- Guide: Uninstall Spyware Doctor
- 中级7 Doctor Death
- Codeforces 83B Doctor
- Spyware Doctor ver. 5.0.0.169
- 神秘博士 Doctor.Who.2005
- Appium-doctor不是内部命令
- Hard working on being a Doctor!
- Lesson 63 Thank you, doctor.谢谢你,医生
- brew doctor老有个Python的警告
- Doctor ANS为服务器健康保驾护航!
- Doctor ANS为服务器健康保驾护航!
- Java学习路线
- [Poi2012] bzoj 2788 Festival
- D
- 在eclipse中使用Maven创建spring+springMVC工程
- 解决:Unable to create project from archetype [org.apache.maven.archetypes:maven-archetype-quickstart……
- CF83B:Doctor(二分)
- Python:类的组合
- Rhel yum源配置
- What/How/Why(学习技术三部曲)
- NOIP2016-普及组复赛-第2题-回文日期
- 工作-2017.08.13-周记总结篇(三)
- 安卓文件读写二,对不同文件的处理要点
- 安卓测试和iOS测试的区别
- codeforces 837A