poj2376 Cleaning Shifts
来源:互联网 发布:知乎 西方哲学史 编辑:程序博客网 时间:2024/04/30 07:09
也是贪心 不过这道随便想想就明白了。。
按起点先后排序,第一个点肯定要选,每次在上一个的终点或者终点+1为起点的点里面选一个终点最远的。
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3fusing namespace std;struct node{ int s,e;}cow[25010];int cmp(node a,node b){ if(a.s==b.s) return a.e>b.e; return a.s<b.s;}int main(){ int n,t,i,j,cnt,tmp,ans; while(~scanf("%d%d",&n,&t)) { for(i=0;i<n;i++) scanf("%d%d",&cow[i].s,&cow[i].e); sort(cow,cow+n,cmp); if(cow[0].s>1) { printf("-1\n"); continue; } ans=1;cnt=0; for(i=0;i<n;) { tmp=0; for(j=i+1;j<n;j++) { if(cow[j].s>cow[cnt].e+1) break; if(cow[j].s>=cow[cnt].s&& cow[j].e>cow[cnt].e) if(cow[j].e>cow[tmp].e) tmp=j; } if(!tmp) i++; else { cnt=tmp; ans++; i=cnt; } } if(cow[cnt].e==t) printf("%d\n",ans); else printf("-1\n"); } return 0;}
0 0
- poj2376 Cleaning Shifts
- POJ2376 Cleaning Shifts 贪心
- poj2376 Cleaning Shifts 贪心
- POJ2376 Cleaning Shifts(贪心)
- POJ2376 Cleaning Shifts 【贪心】
- POJ2376-Cleaning Shifts
- POJ2376贪心Cleaning Shifts
- poj2376 Cleaning Shifts
- POJ2376 Cleaning Shifts(贪心)
- [POJ2376]Cleaning Shifts
- POJ2376 Cleaning Shifts (贪心)
- poj2376 Cleaning Shifts
- poj2376 Cleaning Shifts(区间贪心)
- poj2376(Cleaning Shifts)贪心算法
- 区间贪心:POJ2376--Cleaning Shifts
- POJ2376-Cleaning Shifts-区间贪心
- POJ2376--Cleaning Shifts(贪心)
- POJ2376 Cleaning Shifts (贪心)
- 批量转换文件名
- 物体剔除代码+解析
- android 自定义Toast & 如何使Toast随Activity消失而消失
- win7下通过cocos2d-x2.1.5创建安卓项目解决方案
- PHP读取文件的常见方法
- poj2376 Cleaning Shifts
- 更改sql server 数据库排序规则
- PHP运行出现Notice : Use of undefined constant 的解决办法
- android 设置默认launcher 附上代码
- OpenCv IplImage 转 cv::Mat
- 画线
- equals方法及对其进行重写
- poj 3262 Protecting the Flowers (贪心)
- 关于学java要掌握的知识问题