HDU1031 排序题

/*
 * Author:lonelycatcher
 * Problem:HDU 1031
 * Type:排序水题
 */
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int N,M,K;
struct node
{
 double value;
 int index;
};
node nodes[1000000];
int cmp1(const void* a,const void* b)
{
 node c=*(node*)a;
 node d=*(node*)b;
 if(fabs(d.value-c.value)<0.000001)return c.index-d.index;
 return d.value-c.value;
}
int cmp2(node a, node b)
{
 return a.index>b.index;
}
int main()
{
 setbuf(stdout,NULL);
 int i,j;
 while(scanf("%d %d %d",&N,&M,&K)!=EOF)
 {
  for(i=0;i<M;i++)
  {
   nodes[i].index=i+1;
   nodes[i].value=0;
  }
  double v;
  for(i=1;i<=N;i++)
  {
   for(j=0;j<M;j++)
   {
    scanf("%lf",&v);
    nodes[j].value+=v;
   }
  }
  qsort(nodes,M,sizeof(nodes[0]),cmp1);
  sort(nodes,nodes+K,cmp2);
  for(i=0;i<K;i++)
  {
   if(i==K-1){printf("%d\n",nodes[i].index);break;}
   printf("%d ",nodes[i].index);
  }
 }
 return 0;
}

posted on 2011-08-01 08:12  lonelycatcher  阅读(483)  评论(0编辑  收藏  举报

导航