Design T-Shirt

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4372    Accepted Submission(s): 2126

Problem Description
Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA found that he was trapped by all kinds of suggestions from everyone on the board. It is indeed a mission-impossible to have everybody perfectly satisfied. So he took a poll to collect people's opinions. Here are what he obtained: N people voted for M design elements (such as the ACM-ICPC logo, big names in computer science, well-known graphs, etc.). Everyone assigned each element a number of satisfaction. However, XKA can only put K (<=M) elements into his design. He needs you to pick for him the K elements such that the total number of satisfaction is maximized.
 
Input
The input consists of multiple test cases. For each case, the first line contains three positive integers N, M and K where N is the number of people, M is the number of design elements, and K is the number of elements XKA will put into his design. Then N lines follow, each contains M numbers. The j-th number in the i-th line represents the i-th person's satisfaction on the j-th element.
 
Output
For each test case, print in one line the indices of the K elements you would suggest XKA to take into consideration so that the total number of satisfaction is maximized. If there are more than one solutions, you must output the one with minimal indices. The indices start from 1 and must be printed in non-increasing order. There must be exactly one space between two adjacent indices, and no extra space at the end of the line.
 
Sample Input
3 6 4
2 2.5 5 1 3 4
5 1 3.5 2 2 2
1 1 1 1 1 10
3 3 2
1 2 3
2 3 1
3 1 2
 
Sample Output
6 5 3 1
2 1
 
Author
CHEN, Yue
 
Source
 
 #include <stdio.h>
#include <stdlib.h>
#define MAX 1000 typedef struct IN
{
double a;
int b;
}IN; IN st[MAX]; int cmp(const void *a,const void *b)
{
struct IN *c = (IN *)a;
struct IN *d = (IN *)b;
if(c->a!=d->a)
return d->a - c->a > ? : -;
else
return c->b - d->b;
} int cmpcmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
} int main()
{
int N,M,K;
while(scanf("%d %d %d",&N,&M,&K)!=EOF)
{
int i,j,k,t;
double sum=;
double **s;
int *a;
a=(int *)malloc(K*sizeof(int));//申请一维动态数组
s=(double **)malloc(N*sizeof(double *));
for(i=;i<N;i++)
s[i]=(double *)malloc(M*sizeof(double));//申请二维动态数组
for(i=;i<N;i++)
for(j=;j<M;j++)
{
scanf("%lf",&s[i][j]);
}
for(j=,k=;j<M;j++)
{
sum=;
for(i=;i<N;i++)
{
sum+=s[i][j];
}
st[k].a=sum;
st[k++].b=j;
}
qsort(st,M,sizeof(st[]),cmp);
for(i=;i<K;i++)
a[i]=st[i].b;
qsort(a,K,sizeof(a[]),cmpcmp);
for(i=K-;i>;i--)
printf("%d ",a[i]+);
printf("%d\n",a[]+);
free(a);//释放申请的空间
for(i=;i<N;i++)
free(s[i]);//释放申请的空间
}
return ;
}
 

hdu_1031_Design T-Shirt_201310291647的更多相关文章

随机推荐

  1. [Swift通天遁地]二、表格表单-(6)创建美观的表格弹性下拉刷新效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. Ubuntu中安装部署Intel CS WebRTC

    1环境要求 组件 版本要求 OS CentOS* 7.4, Ubuntu 14.04/16.04 LTS Node 8.11.* (推荐8.11.1) MongoDB 2.4.9 Boost 1.65 ...

  3. OI——不后悔的两年

    NOI2014,悲惨的考跪,99+170+130 399 Cu滚粗.最终签到了复旦的一本,还算是有点结果吧.(其实我一开始就想读复旦我会说?)回首这两年,就像一场梦一样,从一无所知的小白到进入省队再到 ...

  4. JVM中线程状态转换图

    JVM中线程的状态转换图 线程在一定条件下,状态会发生变化.线程一共有以下几种状态: 1.新建状态(New):新创建了一个线程对象. 2.就绪状态(Runnable):线程对象创建后,其他线程调用了该 ...

  5. TensorFlow学习---入门(一)-----MNIST机器学习

    参考教程:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html 数据下载地址:http://wiki.jikexueyuan.com ...

  6. python编辑csv

    import csv import time def timestamp_to_timestr(timeStamp): timeArray = time.localtime(int(timeStamp ...

  7. 2015.12.20-2015.12.25 大论文迭代 A

    进一步充实大论文内容.结构,完善一遍大论文 12.20周天,完成论文第五章总结部分,和第一章的修改 12.21周一,完成论文第二章的修改充实 12.22周二,完成论文第三章的修改充实 12.23周三, ...

  8. C# Tuple 创建一个新二元集合

    List<string> list1=new List<string>(); List<string> list2=new List<string>() ...

  9. javascript 大数据处理方法

    随着前端的飞速发展,在浏览器端完成复杂的计算,支配并处理大量数据已经屡见不鲜.那么,如何在最小化内存消耗的前提下,高效优雅地完成复杂场景的处理,越来越考验开发者功力,也直接决定了程序的性能. 本文展现 ...

  10. Android之手机振动和振铃

    一.振动的实现1.使用振动所需的权限 <uses-permission android:name="android.permission.VIBRATE" />2.相关 ...