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. hdu5698瞬间移动(组合数,逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  2. P3199 [HNOI2009]最小圈

    传送门 据rqy说有这么一个结论\[ans=\min_{v \in V,F_n(v)\neq \infty} \max_{0 \leq k \leq n - 1} \left[\frac{F_n(v) ...

  3. [Swift通天遁地]二、表格表单-(18)快速应用多种预定义格式的表单验证

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

  4. HTML--使用下拉列表框,节省空间

    下拉列表在网页中也常会用到,它可以有效的节省网页空间.既可以单选.又可以多选.如下代码: 讲解: 1.value: 2.selected="selected": 设置selecte ...

  5. SPOJ 1811 SAM 初探

    思路: 一个串建SAM 另一个串在SAM上跑 //By SiriusRen #include <cstdio> #include <cstring> #include < ...

  6. mybatis中打印sql语句

    在mybatis-config.xml中properties节点下,配置一个settings节点 <settings> <setting name="cacheEnable ...

  7. 【转】Java 集合系列08之 List总结(LinkedList, ArrayList等使用场景和性能分析)

    概要 前面,我们学完了List的全部内容(ArrayList, LinkedList, Vector, Stack). Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例 Ja ...

  8. Node.js的运行

    nodejs的运行 首先要在你的电脑上下载node.js并安装,大家可以去官网下载 1.第一种方法:去官网下载git,安装好后,在桌面上单击鼠标右键,会有一个Git Bash Here,然后在新建一个 ...

  9. html——相对路径、绝对路径(有待补充....)

    相对路径主要看你访问的文件相对自己的页面在哪个文件夹下.如果自己藏的很深,必须用“../”跳出.如果项目中的文件位置分布是这样: 那么index页面若要访问这两张图片就需要用相对路径: <img ...

  10. ASP.NET 缓存(Cache)

    ASP.NET提供了在一个ASP.NET应用程序基本上缓存信息的编程功能.该功能和Application对象相似,但它具有在ASP.NET应用程序的生命周期内动态维护缓存信息的能力.在应用程序中缓存数 ...