Design T-Shirt


Time Limit: 2 Seconds      Memory Limit: 32768 KB

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

思路:   把每一个元素的评分加总, 按评分降序排一下,相同评分内部再按照序号升序排一下。
#include <iostream>
#include <stdio.h>
#include <algorithm> using namespace std; struct dat
{
float num;
int index;
}data[]; bool cmp(dat a, dat b)
{
if(a.num != b.num)
return a.num > b.num;
else
return a.index < b.index;
} int main()
{
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=-)
{ float temp=;
for(int i=;i<m;i++)
{
data[i].num = ;
data[i].index = i;
}
for(int i=; i<=n; i++)
{
for(int j=; j<m; j++)
{
scanf("%f", &temp);
data[j].num += temp;
}
} sort(data, data+m, cmp); // for(int i=0; i<m; i++)
// {
// printf("%f---%d\n", data[i].num, data[i].index);
// } int ans[k+]; for(int i=; i<k; i++)
{
ans[i]=data[i].index+;
}
sort(ans, ans+k, greater<int>()); for(int i=; i<k; i++)
{
if(i!=k-)
printf("%d ",ans[i]);
else
printf("%d\n", ans[i]);
}
}
return ;
}

zoj_2511 Design T-Shirt 贪心的更多相关文章

  1. 【English】七、常见动词

    一.动词: touch.hear.say.listen touch [tʌtʃ] 触摸 I touch the cat. They touch the elephant. hear  [hɪr] 听到 ...

  2. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  3. HDU 5835 Danganronpa (贪心)

    Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...

  4. 贪心:SPOJ Backup Files

    BACKUP - Backup Files no tags  You run an IT company that backs up computer data for large offices. ...

  5. cf472B Design Tutorial: Learn from Life

    B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...

  6. 算法设计手冊(第2版)读书笔记, Springer - The Algorithm Design Manual, 2ed Steven S.Skiena 2008

    The Algorithm Design Manual, 2ed 跳转至: 导航. 搜索 Springer - The Algorithm Design Manual, 2ed Steven S.Sk ...

  7. Codeforces Round #270--B. Design Tutorial: Learn from Life

    Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...

  8. LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)

    Best Time to Buy and Sell Stock Total Accepted: 14044 Total Submissions: 45572My Submissions Say you ...

  9. UVA 11039-Building designing【贪心+绝对值排序】

    UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...

随机推荐

  1. 自动由@3x图片生成@2x和@1x的图片 - Xcode插件

    原文:http://www.cocoachina.com/bbs/read.php?tid=277187 生成@3x图片对应的@2x和@1x版本--RTImageAssets 关键字:Xcode插件, ...

  2. python class类的属性应用及init初始化实践 ---勇者斗恶龙

    最近在熟悉python的基础语法,刚好老师布置了个课后作业感觉挺有意思的,就记录下来了学习过程. 题目如下: 刚拿到题目就想到了init 初始化属性,还列了下思路:(ps:notepad++写的比较糙 ...

  3. 1058 A+B in Hogwarts (20分)(水)

    If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- a ...

  4. 数据库学习 day1 认识数据库

    从SQL的角度而言,数据库是一个以某种有组织的方式储存的数据集合. 我们可以把它比作一个“文件柜”,这个“文件柜”是一个存放数据的物理位置,不管数据是什么,也不管数据是如何组织的. 下面介绍几个术语 ...

  5. 【Linux】Linux(一)Linux常用命令

    一 命令行提示符 1.[root@localhost ~]# 当前登录用户@主机名:当前所在目录$ # 超级用户 $  普通用户 当前所在目录:~ 用户家目录 管理员 /root 普通用户 /home ...

  6. 【图机器学习】cs224w Lecture 7 - 节点的表示

    目录 Node Embedding Random Walk node2vec TransE Embedding Entire Graph Anonymous Walk Reference 转自本人:h ...

  7. 127.0.0.1和localhost区别

  8. go中的线程的实现模型-P G M的调度

    线程实现模型 go中线程的实现是依靠 P G M M machine的缩写.一个M代表一个内核线程,或称“工作线程” P processor的缩写.一个P代表执行一个Go代码片段所需要的资源(或称“上 ...

  9. Flex Socket与Java通信实例说明(转)

    Flex Socket与Java通信实例说明(转) 这两天一直在flex的Socket ,现在终于懂了很多.由浅到深一步一步深入.慢慢体会实例,虽然实例都是在网上找的,但也经过了我的测试.我比较喜欢注 ...

  10. 数据结构和算法(Golang实现)(28)查找算法-AVL树

    AVL树 二叉查找树的树高度影响了查找的效率,需要尽量减小树的高度,AVL树正是这样的树. 一.AVL树介绍 AVL树是一棵严格自平衡的二叉查找树,1962年,发明者Adelson-Velsky和La ...