- Source Code
#include<iostream> #include<algorithm> using namespace std; struct node { int x, y; }cow[25002]; bool cmp(node a, node b) { return a.x < b.x; } int main() { int n, k; while (cin >> n >> k) { bool xx = 0, yy = 0; for (int i = 0; i < n; i++) { cin >> cow[i].x >> cow[i].y; if (cow[i].x == 1) xx = 1; if (cow[i].y == k) yy = 1; } if (xx != 1 || yy != 1) { cout << "-1" << endl; continue; } sort(cow, cow + n, cmp); cow[n].x = 1000003; int start = 0, temp = 0; bool b = 0; int s = 0; for (int i = 0; i < n; i++) { if (cow[i].x <= start+1) { if (cow[i].y > temp) temp = cow[i].y, b = 1; if (cow[i + 1].x > start+1&&b) { start = temp; s++; b = 0; } } } if (start >= k) cout << s << endl; else cout << "-1" << endl; } return 0; }
POJ 2376 Cleaning Shifts
最新推荐文章于 2018-06-17 14:32:28 发布