/*输入n个二元组(xi,yi),统计有多少个二元组(xk,yk)满足: *对于任意xi < xk的二元组,yi > yk; *对于任意yi < yk的二元组, xi > xk *( n<= 10000,ai<= 10000) *排序,然后统计。 */ #include <iostream> #include <algorithm> using namespace std; const int maxn = 10001; struct point { int d; int c; }; point arr[maxn]; int N, nCount; void funcInput(); void funcSolve(); void funOutput(); bool cmp(const point &a, const point &b); int main() { while (1 == scanf("%d", &N), N) { funcInput(); funcSolve(); funOutput(); } return 0; } void funcInput() { for(int i = 1; i <= N; i++) { scanf("%d %d", &arr[i].d, &arr[i].c); } } void funcSolve() { int i; /*按distance从小到大排列*/ sort(&arr[1], &arr[N+1], cmp); int nTemp = arr[1].c; nCount = 1; for(i = 2; i <= N; i++) { if(arr[i].c < nTemp) { nCount ++; nTemp = arr[i].c; } } } void funOutput() { printf("%d/n", nCount); } bool cmp(const point &a, const point &b) { if(a.d == b.d) { return a.c < b.c; } else { return a.d < b.d; } } poj 1828 /*输入n个二元组(xi,yi),统计有多少个二元组(xk,yk)满足: *对于任意xi > xk的二元组,yi > yk; *( n<= 10000,ai<= 10000) *排序,然后统计。 */ #include <iostream> #include <algorithm> using namespace std; const int maxn = 50001; struct point { int d; int c; }; point arr[maxn]; int N, nCount; void funcInput(); void funcSolve(); void funOutput(); bool cmp(const point &a, const point &b); int main() { while (1 == scanf("%d", &N), N) { funcInput(); funcSolve(); funOutput(); } return 0; } void funcInput() { for(int i = 1; i <= N; i++) { scanf("%d %d", &arr[i].d, &arr[i].c); } } void funcSolve() { int i; /*按distance从小到大排列*/ sort(&arr[1], &arr[N+1], cmp); int nTemp = arr[1].c; nCount = 1; for(i = 2; i <= N; i++) { if(arr[i].c > nTemp) { nCount ++; nTemp = arr[i].c; } } } void funOutput() { printf("%d/n", nCount); } bool cmp(const point &a, const point &b) { if(a.d == b.d) { return a.c > b.c; } else { return a.d > b.d; } }