zoj_2511 Design T-Shirt 贪心
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 贪心的更多相关文章
- 【English】七、常见动词
一.动词: touch.hear.say.listen touch [tʌtʃ] 触摸 I touch the cat. They touch the elephant. hear [hɪr] 听到 ...
- 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 ...
- HDU 5835 Danganronpa (贪心)
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- 贪心:SPOJ Backup Files
BACKUP - Backup Files no tags You run an IT company that backs up computer data for large offices. ...
- cf472B Design Tutorial: Learn from Life
B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...
- 算法设计手冊(第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 ...
- 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 ...
- 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 ...
- UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...
随机推荐
- A 修公路
时间限制 : - MS 空间限制 : 65536 KB 评测说明 : 时限1000ms 问题描述 某岛国有n个小岛构成(编号1到n),该国政府想要通过n-1条双向公路将这些小岛连接起来,使得任意 ...
- 从 Socket 编程谈谈 IO 模型(三)
快过年啦,估计很多朋友已在摸鱼的路上.而我为了兄弟们年后的追逐,却在苦苦寻觅.规划,导致文章更新晚了些,各位猿粉谅解. 上期分享,我们结合新春送祝福的场景,通过一坨坨的代码让 BIO.NIO 编程过程 ...
- 版本控制,svn基础,实战案例,RPM打包
版本控制,svn基础,实战案例,RPM打包 案例1:Subversion基本操作 案例2:使用Subver ...
- R语言—如何安装Github包的解决方法,亲测有效
R语言—如何安装Github包的解决方法,亲测有效 准备安装材料: R包-REmap GitHub下载地址:https://github.com/lchiffon/REmap R包-baidumap ...
- 【django基础】django接口 异步ajax请求 导出数据库成excel表(包裹前端后端)
py文件: from django.utils.http import urlquote from rest_framework.views import APIView from django.sh ...
- 28.2 api-- System (gc、arraycopy、exit)
/* * System:包含一些有用的类字段和方法.它不能被实例化 * static void arraycopy(Object src, int srcPos, Object dest, int d ...
- "二号标题"组件:<h2> —— 快应用组件库H-UI
 <import name="h2" src="../Common/ui/h-ui/text/c_h2"></import> < ...
- SQL基础系列(4)-性能优化建议
10.1 连接查询表的顺序问题 SQLSERVER的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表driving table)将被最先处理,在FROM子句中包 ...
- 使用 Python 查看局域网内存活主机
1 安装 (如果误用了 pip insatll nmap的话,要先 pip uninstall nmap) pip install python-nmap Nmap 是一款用于网络发现和安全审计的网络 ...
- bat中的特殊字符,以及需要在bat中当做字符如何处理
bat中的特殊字符,以及需要在bat中当做字符如何处理 (2014-02-27 21:16:55) 转载▼ 标签: bat 特殊字符 分类: develop bat中的特殊字符,以及需要在bat中当做 ...