Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

超时 快排+二分,?

Posted by lyl625760 at 2008-11-30 14:06:10 on Problem 3636
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator