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. Ballot evaluation

    http://acm.hdu.edu.cn/showproblem.php?pid=2986 题意很简单,主要是要处理精度,最手残的是把单词拼写错了... #include <stdio.h&g ...

  2. P1452 Beauty Contest

    传送门 求凸包周长,用旋转卡壳,具体可见yyb大佬的博客 顺便一提这题暴力+随机化也能过 暴力代码 //minamoto #include<bits/stdc++.h> #define r ...

  3. akka设计模式系列

    由于本人爱好Scala,顺便也就爱好Akka,但目前网上对Akka的介绍大多都是概念上或技术方向上的介绍,基本没有Akka设计模式或者Actor模型设计模式的资料.这对于Akka的普及非常不利,因为即 ...

  4. $CF1141A Game 23$

    这题很简单啊 可以用\(DFS\)来打 毕竟是 \(2^x*3^y=m 输出x+y啊\) 这是最简单的做法 #include <bits/stdc++.h> using namespace ...

  5. [转]linux之初识SELinux

    转自:http://www.linuxidc.com/Linux/2014-07/104447.htm 1.selinux的概述 selinux相信大家一定不会陌生,它的全称是内核级加强型防火墙.在服 ...

  6. 设置靠近 水平居中的主体内容Div 的 左侧位置固定的Div

    示例效果: 1.主体内容的divMain 水平居中: 2.divLeft 靠近divMain ,位置固定,不随垂直滚动条而动: 相关代码: <html> <head runat=&q ...

  7. MyBatis分页组件--PageHelper

    一.介绍 PageHelper是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 Oracle.Mysql.MariaDB.SQLite.Hsqldb 等. 官网 ...

  8. ajax不跳转页面的快速删除操作,可添加美观样式

    以前我们讲的删除是利用嵌入php代码,跳转到另一个页面,从而降低了删除速度,但我们今天讲的利用ajax不仅可以达到不跳页面快速删除,并且能添加特效来美化页面. 上代码,我们先来做主页面 <!DO ...

  9. PHP中单例模式与工厂模式

    单例模式概念 单例模式是指整个应用中类只有一个对象实例的设计模式. 单例模式的特点 一个类在整个应用中只有一个实例 类必须自行创建这个实例 必须自行向整个系统提供这个实例 php中使用单例模式的原因 ...

  10. 显示log里的ansi codecs颜色字符

    方法: vim AnsiEsc插件 http://www.vim.org/scripts/script.php?script_id=302 less -r cat和tail命令都可以正常显示,而且ta ...