#include<stdio.h> #include<string.h> #include<queue> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; const int MOD=1e9+7; typedef long long LL; int a[N], b[N]; int c[N]; int vis[N]; int main () { int T, n, i; scanf("%d", &T); while (T--) { scanf("%d", &n); memset(vis, 0, sizeof(vis)); for (i = 0; i < n; i++) { scanf("%d%d", &a[i], &b[i]); c[i] = a[i]; c[i+n] = b[i]; } sort(c, c+2*n); for (i = 0; i < n; i++) { int indexa = lower_bound(c, c+2*n, a[i]) - c; ///在c数组中找到第一个>=a[i]的位置(该位置就是离散化后的a[i]) int indexb = lower_bound(c, c+2*n, b[i]) - c; vis[indexa]++; vis[indexb+1]--; } int ans = 0, Max = -INF; for (i = 0; i < 2*n; i++) { ans += vis[i]; if (ans > Max) Max = ans; } printf("%d\n", Max); } return 0; }
HDU 5124 lines(BestCoder Round #20)
原文:http://www.cnblogs.com/syhandll/p/4940814.html