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

Re:请教只排一次序的算法,我排了两次,1xxxMS

Posted by 147465758 at 2005-12-31 11:03:33 on Problem 2726
In Reply To:Re:请教只排一次序的算法,我排了两次,1xxxMS Posted by:semiconductor at 2005-11-13 20:50:42
> //E
> #include <stdio.h>
> #include <memory.h>
> #include <algorithm>
> using namespace std;
> #define N 10000
> int dis[N],price[N];
> int myindex[N];
> bool cmp(int a,int b)
> {
> 	return dis[a]<dis[b]||(dis[a]==dis[b]&&price[a]<price[b]);
> }
> int solve(int n)
> {
> 	int i,pre=100000000,re=0;
> 	for ( i=0;i<n;i++ )myindex[i]=i;
> 	sort(myindex,myindex+n,cmp);
> 	for ( i=0;i<n;i++ )
> 	{
> 		if ( price[myindex[i]]<pre)
> 		{
> 			pre=price[myindex[i]];
> 			re++;
> 		}
> 	}
> 	return re;
> }
> int main()
> {
> 	int n,i;
> 	while ( scanf("%d",&n),n )
> 	{
> 		for ( i=0;i<n;i++ )scanf("%d %d",dis+i,price+i);
> 		printf("%d\n",solve(n));
> 	}
> 	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