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. windows2003下svn的安装

    Windows2003下svn平台搭建 编辑:dnawo 日期:2010-08-03 转自http://www.mzwu.com/article.asp?id=2557 字体大小: 小 中 大     ...

  2. [Swift通天遁地]八、媒体与动画-(6)使用开源类库快速实现滑入动画

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

  3. Java Itext 生成PDF文件

    利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...

  4. php 获取客户端的真实ip地址 通过第三方网站

    <?php include 'simple_html_dom.php'; // 1获取真实IP地址方式 function get_onlineip() { $ch = curl_init('ht ...

  5. fastjson读取json配置文件

    fastjson读取json配置文件: ClassLoader loader=FileUtil.class.getClassLoader(); InputStream stream=loader.ge ...

  6. MVC系列学习(八)-分布视图

    1.本次学习实例 1.1.建议:为了尽可能让项目简单,就新建一个空的mvc项目,同时添加任何视图不用模板页 1.2注意:在添加LoginPart的分部视图时,要记得沟一个沟 2.项目代码,如下 总共三 ...

  7. 实现strcpy

    #include <stddef.h> char* strcpy(char* dest, const char* src) { if (dest == NULL || src == NUL ...

  8. 关于debug.keystore文件用法以及错误处理

    在开发过程中需要频繁的为测试的同事签名apk,非常很麻烦,把默认debug.keystore文件替换成发布用(生产环境)的签名文件,不用频繁地签名apk文件了.      如果直接使用生产keysto ...

  9. 移动web——轮播图

    1.我们将5张图片又前后各增加一张,第一张前增加的是原本的第五张,第五张后增加的是原本的第一张,增加的原因无非是手指滑动的时候有轮播效果,这不像以前的轮播图,点击图标就能立刻将ul跳转到指定位置,手机 ...

  10. IP访问频率限制不能用数组循环插入多个限制条件原因分析及解决方案

    14.IP频率限制不能用数组循环插入多个限制条件原因分析及解决方案: define("RATE_LIMITING_ARR", array('3' => 3, '6' => ...