标签:des style blog http io ar color os sp
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 787 Accepted Submission(s): 194
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<stack> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const double EPS=1e-8; const int MAXN=100000+5; int a[MAXN*2],b[MAXN*2]; struct node { int star,en; }line[MAXN]; int bs(int a[],int x,int val) { int l=0,r=x-1; while(l<=r) { int mid=(l+r)/2; if(a[mid]==val) return mid; if(val>a[mid]) l=mid+1; else r=mid-1; } } int main() { int kase,n; scanf("%d",&kase); while(kase--) { int cnt=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&line[i].star,&line[i].en); a[cnt++]=line[i].star; a[cnt++]=line[i].en; //将端点记录在a数组中 } sort(a,a+cnt); //排序的话,可以说是一个离散化处理 int p=1; for(int i=1;i<cnt;i++) if(a[i]!=a[i-1]) a[p++]=a[i]; //删除重复的端点 for(int i=0;i<n;i++) { int vis; vis=bs(a,p,line[i].star); b[vis]++; vis=bs(a,p,line[i].en); b[vis+1]--; } int maxn=b[0]; for(int i=1;i<p;i++) { b[i]=b[i-1]+b[i]; if(b[i]>maxn) maxn=b[i]; } printf("%d\n",maxn); } return 0; }
BestCoder Round #20 lines (模拟线段树的思想)
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/clliff/p/4134666.html