codeforces 551 C GukiZ hates Boxes
来源:互联网 发布:淘宝4px递四方速递运费 编辑:程序博客网 时间:2024/03/29 00:12
……睡太晚了。。。脑子就傻了……
这个题想的时候并没有想到该这样……
题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最开始都站在第一个箱子的左边,
每一个人在每一秒钟都必须做出两种选择中的一种:1若他的位置有箱子则搬走一个箱子,2往右走一步。
问把所有箱子都搞掉的最少时间……
很显然二分一下答案,若为x秒,则每个人都有x秒,一个一个排出去搬,看是否能够搬完……
我竟然没想到……
#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<climits>#include<list>#include<iomanip>#include<stack>#include<set>using namespace std;typedef long long ll;int a[100010];bool isok(int n,int m,ll x){ll t=x;for(int i=0;i<n;i++){int re=a[i];ll t1=t-i-1;if(t1<0){if(m==0)return 0;t1=x-i-1;t=x;m--;}if(re>0){if(t1>=re)t-=re;else{re-=t1;t1=x-i-1;t=x;int t2=re/t1;re-=t2*t1;if(re>0){t2++;t-=re;}elset=0;m-=t2;if(m<0)return 0;}}}return 1;}int main(){int n,m;cin>>n>>m;for(int i=0;i<n;i++)cin>>a[i];for(int i=n-1;i>-1;i--)if(a[i]!=0){n=i+1;break;}ll l=n+1,r=ll(1e15);while(l<=r){ll md=l+r>>1;if(isok(n,m-1,md))r=md-1;elsel=md+1;}cout<<l;}
0 0
- codeforces 551 C GukiZ hates Boxes
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
- codeforces-551C GukiZ hates Boxes
- 551C GukiZ hates Boxes
- Codeforces 551C - GukiZ hates Boxes (二分 + 贪心)
- Codeforces 551C - GukiZ hates Boxes(二分加贪心)
- CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
- Codeforces 551C GukiZ hates Boxes 二分答案
- Codeforces 551C GukiZ hates Boxes(二分答案)
- codeforce 551C GukiZ hates Boxes
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes(二分)
- codeforces #307 C. GukiZ hates Boxes(贪心+二分)
- Codeforces 551C GukiZ hates Boxes【二分+思维处理】好题!
- 二分答案找最优解 codeforces problem/551/C GukiZ hates Boxes
- codeforce 551C GukiZ hates Boxes(二分+贪心)
- Codeforces Round #307 (Div. 2)--C. GukiZ hates Boxes、D. GukiZ and Binary Operations
- Codeforences #307(div2) C . GukiZ hates Boxes
- GukiZ hates Boxes 二分
- Cocos2d-x开发教程 第二节 基本概念
- 每一位Android开发者应该知道的Android体系架构和开发库
- 读Excel表格的两个函数ALSM_EXCEL_TO_INTERNAL_TABLE、KCD_EXCEL_OLE_TO_INT_CONVERT
- 计蒜客第10题---寻找插入位置
- Java实现回调函数
- codeforces 551 C GukiZ hates Boxes
- hdu5296(2015多校1)--Annoying problem(lca+一个公式)
- java中如何终止线程
- IAR8.302破解
- light oj 1248 - Dice (III)(概率dp)
- RMQ专题练习
- 队列相关知识
- 【2015/7/22】SqlServer卸载重装全攻略!
- OC基础_数组