CF 589F 贪心+二分
来源:互联网 发布:网络推广工资怎么样 编辑:程序博客网 时间:2024/04/27 21:31
题意是有N道菜,需要吃到每一种菜,且每种菜要吃相同时间。
那么按时间右端点排序,再依次有空则吃。为什么这样贪心是正确的呢,因为选择更早结束的菜,那么之后就会剩下更多的时间去吃其余的菜,那么贪心是正确的。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=110;int n;bool vis[10010];struct node{ int a,b; bool operator<(const node &x) const { return b<x.b; }}t[maxn];bool check(int mid){ //memset(vis,0,sizeof(vis)); for(int i=0;i<10010;i++) { vis[i]=false; } for(int i=1;i<=n;i++) { if(t[i].b-t[i].a<mid) return false; int cnt=0; for(int j=t[i].a;j<t[i].b;j++) { if(cnt>=mid) break; if(!vis[j]) { vis[j]=true; cnt++; } } if(cnt<mid) return false; } return true;}int bin(int l,int r){ int ans=l; while(l<=r) { int mid=(l+r)>>1; if(check(mid)) { ans=mid; l=mid+1; } else r=mid-1; } return ans;}int main(){ while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { scanf("%d%d",&t[i].a,&t[i].b); } sort(t+1,t+1+n); printf("%d\n",bin(0,t[n].b)*n); } return 0;}
0 0
- CF 589F 贪心+二分
- CF 725F 贪心
- 二分贪心专题F
- 二分贪心 F
- CodeForces 589F -- F. Gourmet and Banquet (二分 + 贪心)
- CF 589F 网络流(or贪心?)
- cf 484B 二分+贪心
- CF 830A 贪心+二分
- 二分贪心 F 切网线
- ACM-二分贪心F-06
- codeforce 589F(二分 +(贪心 or 网络流))
- CodeForces 589F Gourmet and Banquet(贪心+二分)
- Codeforces 589F Gourmet and Banquet(二分+贪心)
- CodeForces 589F:Gourmet and Banquet(二分+贪心)
- cf 830A Office Keys 【二分+贪心】
- CF 363D. Renting Bikes 贪心+二分
- codeforces 589F(二分)
- CF 329B(Biridian Forest-贪心-非二分)
- Ajax(1)
- CodeForces 372 A Counting Kangaroos is Fun
- 如何创建并运行Java线程
- JSTL的配置与使用
- 【CodeForces】699C - Vacations(贪心)
- CF 589F 贪心+二分
- java.nio系列二
- java.nio系列二
- 5-29 修理牧场
- hdu1251-字符前缀查找问题 map容器
- Codeforces 448D Multiplication Table(二分)
- 科学与艺术
- SlidingMenu+Fragment组合
- C语言实验——整数位(用顺序表)