lines-HDU5124(区间处理 +离散化)
Problem Description
John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A.
Input
The first line contains a single integer T(1≤T≤100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
Output
For each case, output an integer means how many lines cover A.
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
Sample Output
3
1
题目大意:
给你几个区间,然后给这区间间的点染色
求最染色最多的点 染了多少色
分析:
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> using namespace std; #define N 1100000 struct node { int x,y; }a[N]; int f[N],p[N]; int main() { int T,n,i; scanf("%d",&T); while(T--) { int k=0; memset(a,0,sizeof(a)); memset(f,0,sizeof(f)); memset(p,0,sizeof(p)); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&a[i].x,&a[i].y); p[k++]=a[i].x; p[k++]=a[i].y; } sort(p,p+k); int len=unique(p,p+k)-p; int Max=0; for(i=0;i<n;i++) { int u=lower_bound(p,p+len,a[i].x)-p; int v=lower_bound(p,p+len,a[i].y)-p; f[u]++; f[v+1]--; Max=max(Max,v+1); } int ans=0,b=0; for(i=0;i<=Max;i++) { ans+=f[i]; b=max(b,ans); } printf("%d\n",b); } return 0; }