标签:
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1375 Accepted Submission(s): 571
题意:给你n个区间覆盖x轴,问哪个点被覆盖的线段数多,是几条。
由于数据范围太大,所以离散化……
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 500008 struct node { int op,num; }P[maxn]; int cmp(node a, node b) { return a.op < b.op; } int main() { int t, n, x, y; scanf("%d", &t); while(t--) { scanf("%d", &n); int k = 0, j; for(int i = 0; i < n; i++) { scanf("%d%d", &x, &y); P[k].op = x; P[k++].num = 1; P[k].op = y+1; P[k++].num = -1; } sort(P, P+k, cmp); int cnt = 0, Max = 0; for(int i = 0; i < k; ) { j = i; while(P[j].op == P[i].op && j < k) { cnt += P[j].num; j++; } i = j; Max = max(Max, cnt); } printf("%d\n", Max); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4948096.html