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

WA*5~~~请教大牛,哪里出错了?谢谢

Posted by bluetiger at 2006-01-01 11:55:21 on Problem 2726
#include<stdio.h>
#include<stdlib.h>
int d[10001],c[10001],index[10001];
int cmp(const void *a,const void *b)
{
    int i=*(int*)a,j=*(int*)b;
    return d[i]>d[j]||(d[i]==d[j]&&c[i]>c[j]);
}    
int main()
{
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,n,s,price;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<n;i++)scanf("%d %d",&d[i],&c[i]);
        for(i=0;i<n;i++)index[i]=i;
        qsort(index,n,sizeof(index[0]),cmp);
        price=100000000;
        s=0;
        for(i=0;i<n;i++)
        {
            //printf("%d %d %d\n",index[i],d[index[i]],c[index[i]]);
            if(c[index[i]]<price)
            {
                price=c[index[i]];
                s++;
            }    
        }    
        printf("%d\n",s);
    }    
    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