CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
来源:互联网 发布:编程一个球从100米落下 编辑:程序博客网 时间:2024/05/17 02:38
m个人要去移动n堆盒子 每堆上有若干个盒子 每个人只能进行两种操作 从一个位置走到下一个位置 如果这个位置上的盒子个数不为0 那么就要把这个位置上的盒子移掉 每种操作需要一秒
求这m个人 把盒子全都清掉所花的最少时间
二分所需要的时间 对每个人进行贪心 从最远的地方开始 让每个人在时间范围内移动更多数目的盒子堆数
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 100010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int Read(){ char c = getchar(); while (c < '0' || c > '9') c = getchar(); int x = 0; while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x;}void Print(int a){ if(a>9) Print(a/10); putchar(a%10+'0');}ll n,m;ll num[MAXN];int Check(ll x){ ll cnt=m; ll id=n+1; ll tmp=0; while(cnt--) { ll y=x; while(tmp==0) { if(id==1) return 1; tmp=num[--id]; } if(y<=id) return 0; y-=id; while(y>=tmp) { y-=tmp; tmp=0; while(tmp==0) { if(id==1) return 1; tmp=num[--id]; } } tmp-=y; if(tmp==0&&id==1) return 1; } return 0;}int main(){// fread; while(scanf("%I64d%I64d",&n,&m)!=EOF) { ll l=1,r=0; for(ll i=1;i<=n;i++) { scanf("%I64d",&num[i]); r+=(num[i]+i); } while(l<r) { ll mid=(l+r)/2; if(Check(mid)) r=mid; else l=mid+1; } printf("%I64d\n",l); } return 0;}
0 0
- CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
- Codeforces 551C - GukiZ hates Boxes (二分 + 贪心)
- Codeforces 551C - GukiZ hates Boxes(二分加贪心)
- codeforce 551C GukiZ hates Boxes(二分+贪心)
- Codeforces 551C GukiZ hates Boxes(二分答案)
- codeforces #307 C. GukiZ hates Boxes(贪心+二分)
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes (贪心 + 二分)
- Codeforces 551C GukiZ hates Boxes 二分答案
- codeforces 551 C GukiZ hates Boxes
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
- codeforces-551C GukiZ hates Boxes
- [二分、贪心]Codeforces Round #307 (Div. 2) C.GukiZ hates Boxes
- cf#307-C - GukiZ hates Boxes-二分+贪心
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes(二分)
- Codeforces551C:GukiZ hates Boxes(二分+贪心)
- Codeforces551C:GukiZ hates Boxes(二分+贪心)
- 551C GukiZ hates Boxes
- GukiZ hates Boxes 二分
- 利用全注解实现ssh的一个完整例子
- C语言异常处理——setjmp & longjmp
- android studio 测试(增)
- oracle 大对象
- DTO模式的研究
- CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
- 在ubuntu 12.04上安裝Redmine
- Python安装模块出现问题UnicodeDecodeError的解决方法
- 2015062407 - 17824
- markdown基本语法熟悉
- django html 加载静态 js css(windows) pycharm
- How To Install / Configure VNC Server On CentOS 7.
- CheckedTextView的使用、学android疯狂讲义第二版遇到的问题希望能帮到和我一样的初学者、新手
- 2015062507 - 星际迷航.红杉