codeforces 551C(二分)
来源:互联网 发布:淘宝店铺页头装修 编辑:程序博客网 时间:2024/04/28 11:35
题目链接:http://codeforces.com/contest/551/problem/C
题意:
一共有n个空地,数轴1~n,每个空地上有a[i]块石头,有m个学生,目标是删除所有石头,一开始所有学生都站在x=0的地方,一开始所有学生都站在 x=0的地方,问删除所有石头的最短时间
解题思路:
最后一个有石头的空地记为p,石头总和记为ans
那么时间的范围是p~p+ans
二分枚举时间,判断是否满足
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <algorithm>using namespace std;#define ll __int64ll a[100005];int p,n,m;bool check(ll x){ll s=0;int cnt=m;for(int i=1;i<=p;i++){s+=a[i];while(s+i>=x){s-=x-i;cnt--;if(cnt<0) return 0;}}if(cnt==0) return s<=0;return 1;}int main(){scanf("%d%d",&n,&m);ll ans=0,sum;for(int i=1;i<=n;i++){scanf("%I64d",&a[i]);ans+=a[i];if(a[i]) p=i;}ll l=p,r=p+ans;while(l<=r){ll mid = (l+r)>>1;if(check(mid)){sum=mid;r=mid-1;}else{l=mid+1;}}printf("%I64d\n",sum);return 0;}
0 0
- codeforces 551C(二分)
- codeforces 535C(二分)
- CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
- Codeforces 551C GukiZ hates Boxes(二分答案)
- CodeForces 460C--- Present(二分+贪心)
- CodeForces 371C Hamburgers (二分)
- CodeForces--626C--Block Towers (二分)
- Codeforces--645C--Enduring Exodus(二分)
- CodeForces - 645C Enduring Exodus (二分)
- CodeForces 626C Block Towers(二分)
- 【CodeForces】371C - Hamburgers(二分)
- CodeForces 371C Hamburgers (二分)
- Codeforces 371C:Hamburgers(二分)
- 【CodeForces】702C - Cellular Network(二分)
- 【Codeforces】-702C-Cellular Network(二分)
- CodeForces 371C Hamburgers (二分)
- Codeforces 645C 二分
- CodeForces 626C 二分
- Mysql 性能优化(一 慢日志)
- Nginx作为反向代理的简单应用
- Opencv 官方tutorial学习
- mysql绿色版学习
- 生活随感记录
- codeforces 551C(二分)
- 跨浏览器的CSS渐变解决方案
- openfire用户整合 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xxx.xxx' doesn
- P1133装箱问题
- DataGuard备库ORA-01196故障恢复一则
- cocos2d-x初探学习笔记(1)--HelloWorld
- Java7后try-catch块的变化——aotocloseable接口
- GRE写作必备句型
- 【Objective-C】构造方法