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 |
WA*5~~~请教大牛,哪里出错了?谢谢#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator