题目链接:http://poj.org/problem?id=1065
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1051
贪心 先按l升序再按w稳定升序
然后从头扫到尾取可以取的
然后再从头 直到全部取完
一年前第一次写这道题的时候写了两百行Orz 其中有70行归并排序自己手敲
刚刚翻看老代码真是感慨...
#include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <stack> #include <set> #include <queue> #include <vector> using namespace std; typedef long long ll; const int maxn = 5100; const double eps = 1e-7; struct Node { int x, y; bool operator < (const Node &s) const { if(x == s.x) return y < s.y; else return x < s.x; } }a[maxn]; int flag[maxn]; int main() { //freopen("in.txt", "r", stdin); int T; scanf("%d", &T); while(T--) { int ans = 0; memset(flag, 0, sizeof(flag)); int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d%d", &a[i].x, &a[i].y); sort(a, a + n); int cnt = 0; while(cnt < n) { ans++; int pre_x = -1000000; int pre_y = -1000000; for(int i = 0; i < n; i++) { if(!flag[i]) { if(a[i].x >= pre_x && a[i].y >= pre_y) { pre_x = a[i].x; pre_y = a[i].y; cnt++; flag[i] = 1; } } } } printf("%d\n", ans); } return 0; }