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

哪位牛B人可以have a look!彧者给个代码来参考一下!

Posted by wo_top at 2007-11-28 23:35:56 on Problem 1065
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int partition(vector<int>&x,vector<int>&y,int m,int n)
{ 
   
  int v=y[m],u=x[m];
  while(m<n)
  { while(m<n&&y[n]>=v)--n;
    y[m]=y[n];x[m]=x[n];
	while(m<n&&y[m]<=v)++m;
	y[n]=y[m];x[n]=x[m];
  }
  y[m]=v;x[m]=u;
  return m;
}

void quicksort(vector<int>&x,vector<int>&y,int p,int q)
{  int j;
	if(p<q)
{j=partition(x,y,p,q);
 quicksort(x,y,p,j-1);
 quicksort(x,y,j+1,q);
 
}
 
}
void main()
{  vector<int>x,y;
   int n,mc,xi,yi,sum,oneturn,shu;
   cin>>n;
   for(int i=1;i<=n;i++)
   { 
     cin>>mc;
	 for(int j=0;j<mc;j++)
	 { cin>>xi>>yi;
	   
	 x.push_back(xi);
	 y.push_back(yi);
	 }
	
     quicksort(x,y,0,y.size()-1);
     sum=0;
	 
	 
  while(1)
  {   oneturn=0;shu=1;
	  for(int k=0;k<mc;k++)
           
		  
		  if(x[k]!=0)
		  {
			if(shu==1)
			{j=k;
			 x[k]=0;
		    shu=0;
		
			oneturn++;
			}
	         else 
			 {  if(x[k]>=x[j])
			      x[k]=0;
			       j=k;
				   oneturn++;
			  }
		  }
		  sum+=oneturn;
	if(shu==1)
		break;
   }

	 cout<<sum<<endl;
   }
}

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