POJ 2376 Cleaning Shifts
来源:互联网 发布:手机怎样给淘宝评价 编辑:程序博客网 时间:2024/05/02 15:52
简单贪心,trick蛮多的,调了许久~~~
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int MAXN = 25010;const int INF = 0x3f3f3f3f;struct Node{ int l, r; Node() {} Node(int t_l, int t_r) : l(t_l), r(t_r) {} friend bool operator < (const Node &p1, const Node &p2) { if(p1.l == p2.l) return p1.r > p2.r; return p1.l < p2.l; }}p[MAXN];int N, T, total, ans;int main(){ //freopen("aa.in", "r", stdin); //freopen("bb.out", "w", stdout); while(scanf("%d %d", &N, &T) != EOF) { for(int i = 0; i < N; ++i) { scanf("%d %d", &p[i].l, &p[i].r); } sort(p, p + N); if(p[0].l > 1) { printf("-1\n"); } else { int id = 0; total = 0; ans = 0; bool flag = true; while(id < N) { total++; int t_max = -INF; flag = false; while(p[id].l <= total && id < N) { t_max = max(t_max, p[id].r); id++; flag = true; } if(!flag) break; total = t_max, ans++; if(total >= T) break; } if(!flag || total < T) printf("-1\n"); else printf("%d\n", ans); } } return 0;}
- POJ 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- poj 2376 Cleaning Shifts
- POJ-2376-Cleaning Shifts
- poj 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- poj 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- poj 2376 Cleaning Shifts
- POJ-2376 Cleaning Shifts
- POJ 2376Cleaning Shifts
- POJ 2376 Cleaning Shifts
- poj 2376 Cleaning Shifts
- POJ - 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts
- poj 2376 Cleaning Shifts
- JS实现一些日期的比较
- CUDA内存拷贝
- 软文营销必将是又一热点营销法子
- android WebViewClient的方法解释
- 最近几天学到的东西
- POJ 2376 Cleaning Shifts
- CUDA编程
- 【§手绘亲亲木朵(oo)】
- 每日一题(95) - 两个有序数组元素之积、和的最小K个值
- Oracle 创建表空间Sql
- ProgressBar
- sencha touch之carousel
- 模板--高精度、大整数幂取模
- dbca建库脚本——11g