| ||||||||||
| 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 | |||||||||
Re:请教只排一次序的算法,我排了两次,1xxxMSIn Reply To:请教只排一次序的算法,我排了两次,1xxxMS Posted by:bakey at 2005-11-13 20:47:47 //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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator