Codeforences #307(div2) C . GukiZ hates Boxes
来源:互联网 发布:什么是淘宝嘉年华 编辑:程序博客网 时间:2024/05/16 01:58
题目传送门
【题意】m个人要去移动n堆盒子 每堆上有若干个盒子 每个人只能进行两种操作 从一个位置走到下一个位置 如果这个位置上的盒子个数不为0 那么就要把这个位置上的盒子移掉 每种操作需要一秒
求这m个人 把盒子全都清掉所花的最少时间.
【解题思路】二分所需要的时间 对每个人进行贪心 从最远的地方开始 让每个人在时间范围内移动更多数目的盒子堆数m个人要去移动n堆盒子 每堆上有若干个盒子 每个人只能进行两种操作 从一个位置走到下一个位置 如果这个位置上的盒子个数不为0 那么就要把这个位置上的盒子移掉 每种操作需要一秒,求这m个人 把盒子全都清掉所花的最少时间
【具体做法】二分所需要的时间 对每个人进行贪心 从最远的地方开始 让每个人在时间范围内移动更多数目的盒子堆数
//Created Author :just_sort//Created Time :2016/1/23 14:42//Created File :GukiZ hates Boxes.#include <cstdio>#include <cctype>#include <iostream>#include <algorithm>using namespace std;#define ll long longconst int maxn = 100010;int n,m,tot;ll a[maxn];int check(ll x)//在x的时间限制内,是否能搬完所有的box.{ int i,cnt=m; ll s=0; for(i=1;i<=tot;i++) { s+=a[i]; while(s+i>=x)//移动箱子加上走的路程超过了x. { s-=x-i;//对于当前已经走的路程,一个人有x-i的时间来搬箱子,那么每增加一个人,搬箱子的时间减少x-i. cnt--; if(cnt<0)return 0; } } if(cnt==0)return s<=0; return 1;}int main(){ ll l,r,ans,sum=0; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; if(a[i])tot=i;//记录最右边的不为0的数的位置. } l=tot,r=sum+tot;// cout<<l<<" "<<r<<endl; while(l<=r) { ll mid=(l+r)>>1; if(check(mid)) { ans=mid; r=mid-1; } else l=mid+1; } printf("%I64d\n",ans); return 0;}
0 0
- Codeforences #307(div2) C . GukiZ hates Boxes
- 551C GukiZ hates Boxes
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes(二分)
- codeforces #307 C. GukiZ hates Boxes(贪心+二分)
- cf#307-C - GukiZ hates Boxes-二分+贪心
- codeforce 551C GukiZ hates Boxes
- codeforces 551 C GukiZ hates Boxes
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
- codeforces-551C GukiZ hates Boxes
- GukiZ hates Boxes 二分
- Codeforces Round #307 (Div. 2)--C. GukiZ hates Boxes、D. GukiZ and Binary Operations
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes (贪心 + 二分)
- [二分、贪心]Codeforces Round #307 (Div. 2) C.GukiZ hates Boxes
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes (二分)
- Codeforces 551C - GukiZ hates Boxes (二分 + 贪心)
- Codeforces 551C - GukiZ hates Boxes(二分加贪心)
- CodeForces 551 C. GukiZ hates Boxes(二分+贪心)
- Codeforces 551C GukiZ hates Boxes 二分答案
- 九度oj 1153,1019 栈
- UIButton的详细介绍:
- Android view.isShown ()与view.getVisibility() == View.VISIBLE的用法区别
- iOS 抖动动画
- LeetCode(15)-3Sum
- Codeforences #307(div2) C . GukiZ hates Boxes
- Android---JSON的三种解析方式
- 【Jmeter】初步使用(二)
- 使用LayoutInflater布局显示异常
- iOS 获取手机型号
- 解决ubuntu14.04编译boost1.5.4没有thread库生成
- 美观的VIM color scheme配色主题
- HDU1011 树形DP
- nyoj246 Human Gene Functions(LCS变形)