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. 我们的微信小程序开发

    基于微信小程序的系统开发准备工作 腾讯推出微信小程序也有一段时间了,在各种行业里面也都掀起一阵阵的热潮,很多APP应用被简化为小程序的功能迅速推出,同时也根据小程序的特性推出各种独具匠心的应用,相对传 ...

  2. [Swift通天遁地]四、网络和线程-(13)创建一个Socket客户端

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

  3. Appium + python -yaml配置文件

    在线安装:pip install yaml import yamlimport os # 获取当前脚本所在文件夹路径curpath = os.path.dirname(os.path.realpath ...

  4. 多个@bean无法通过@resource注入对应的bean(org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found )

    一.异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ' ...

  5. Akka源码分析-故障恢复

    Actor故障恢复是akka中非常重要的内容,在之前的博客中虽然有介绍,但都是杂糅在其他知识点的细节中,本博客将单独介绍这一部分的故障恢复.为了简化分析的单独,本文只研究用户的actor故障恢复的步骤 ...

  6. vue打包问题:Tip: built files are meant to be served over an HTTP server.

    npm run build之后,出现提示:Tip: built files are meant to be served over an HTTP server. Opening index.html ...

  7. MFC学习篇(二):error LNK2005 及其解决方法

    环境:MFC条件下添加原有代码 >nafxcwd.lib(afxmem.obj) : error LNK2005: @YAPAXI@Z) already defined in LIBCMTD.l ...

  8. 51nod1446 Kirchhoff矩阵+Gauss消元+容斥+折半DFS

    思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using ...

  9. 【1】Jdk1.8中的HashMap实现原理

    HashMap概述 HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变. 内部实现 ...

  10. (转)容易遗忘的JS知识点整理

    1.hasOwnProperty相关 为了判断一个对象是否包含自定义属性而不是原型链上的属性,我们需要使用继承自 Object.prototype 的 hasOwnProperty方法.hasOwnP ...