[题目链接]
http://poj.org/problem?id=1609
[算法]
将坐标按x为第一关键字,y为第二关键字排序
求最长上升子序列即可
[代码]
#include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <map> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <stack> #include <limits.h> using namespace std; #define MAXN 100010 struct info { int x,y; } a[MAXN]; int i,l,r,mid,n,cnt; int q[MAXN]; inline bool cmp(info a,info b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } int main() { while (scanf("%d",&n) != EOF && n) { for (i = 1; i <= n; i++) scanf("%d%d",&a[i].x,&a[i].y); sort(a + 1,a + n + 1,cmp); cnt = 0; for (i = 1; i <= n; i++) { if (i == 1 || a[i].y >= q[cnt]) { q[++cnt] = a[i].y; continue; } l = 1; r = cnt - 1; while (l <= r) { mid = (l + r) >> 1; if (q[mid] <= a[i].y) l = mid + 1; else r = mid - 1; } q[l] = a[i].y; } printf("%d ",cnt); } printf("* "); return 0; }