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:我也是这样写的,是不是比较函数有问题,不怎么懂,哪位帮我看看

Posted by Debugcool at 2009-07-23 08:43:40 on Problem 2675
In Reply To:我也是这样写的,是不是比较函数有问题,不怎么懂,哪位帮我看看 Posted by:zerocool_08 at 2005-10-23 15:56:36
> #include "stdio.h"
> #include "stdlib.h"
> #include "math.h"
> struct song{
>     int  id;
>     int  ln;
>     double fr;
> }a[1<<16];
> int cmp(const void *p1,const void *p2)
> {
>     if( (*(struct song *)p2).fr>(*(struct song *)p1).fr   ) 
>         return 1;
>     if( fabs((*(struct song *)p2).fr==(*(struct song *)p1).fr)<0.000001  )  
>         return 0;
>     return -1;      
>          
> }
> int  main()
> {
>     int  i,n,num;
>     scanf("%d",&n);
>     for(i=0;i<n;i++) 
>     {
>         scanf("%d %d %lf",&a[i].id,&a[i].ln,&a[i].fr);
>         a[i].fr/=a[i].ln;
>     }
>     scanf("%d",&num);
>     qsort(a,n,sizeof(struct song),cmp);
>     printf("%d\n",a[num-1].id);
> }                     
比较 a.len*b.fre<b.len*a.fre 吧,可以过的 
而且你只读了一次数据………………

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