Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
超时 快排+二分,?#include<vector> #include<iostream> using namespace std; struct student { int x; int y; }; int cmp( const void *a ,const void *b) { return (*(struct student *)a).x > (*( struct student *)b).x ? 1 : -1; } int main() { int num; cin>>num; while(num--) { int n; cin>>n; struct student stu[n]; for(int i=0;i<n;i++) cin>>stu[i].x>>stu[i].y; qsort(stu,n,sizeof(stu[0]),cmp); int a[10000]; int m=0; a[0]= stu[0].y; for(int i=1;i<n;i++) { int left=0; int right=m; while(left<=right) { int mid=(left+right)/2; if (a[mid]>=stu[i].y) left=mid+1; else right=mid-1; } if(left==m+1) m++; a[left]=stu[i].y; } cout<<m+1<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator