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 ...
随机推荐
- 原生的js操作实现通过对URL的监控获取参数
原生的js操作实现通过对URL的监控获取用户的操作信息 优化网站的时候,因为列表是用vue组件进行循环渲染,就出现了一个问题,单击跳转的问题,想了很多方案,使用js函数的方式面对这种情况并不乐观,想到 ...
- Java哈希表入门
Java哈希表(Hash Table) 最近做题经常用到哈希表来进行快速查询,遂记录Java是如何实现哈希表的.这里只简单讲一下利用Map和HashMap实现哈希表. 首先,什么是Map和HashMa ...
- Linux基础:Day01
Linux操作系统的知识体系: 1.初级 2.中级 3.高级 4.*额外知识* 1.初级 1.1.OS操作系统的原理 1.2.开始了解常用的命令(系统管理的基础命令) 开机关机 时 ...
- wireshark抓包实战(八),专家分析
专家分析是干什么的?它可以帮你统计当前所抓包中丢包.错包等等的出现概率 其中关键字如下: error ===> 出错包 warning ===> 警告包 note ===> 注意包 ...
- C++ namespace 命名空间
namespace即"命名空间",也称"名称空间" 那么这个 "名称空间" 是干啥的呢? 我们都知道,C/C++中的作用域可以由一个符号 { ...
- 【java设计模式】(7)---策略模式(案例解析)
策略模式 一.概念 1.理解策略模式 策略模式是一种行为型模式,它将对象和行为分开,将行为定义为 一个行为接口 和 具体行为的实现.策略模式最大的特点是行为的变化,行为之间可以相互替换. 每个if判断 ...
- 从零搭建一个SpringCloud项目之Config(五)
配置中心 一.配置中心服务端 新建项目study-config-server 引入依赖 <dependency> <groupId>org.springframework.cl ...
- AJ学IOS 之CoreLocation指南针小应用
AJ分享,必须精品 一:效果图示 简单的用到CoreLocation获取方位做的指南针小应用 二:制作思路 具体用到了CoreLocation相关的知识,请看上一篇博客有写 然后获取方向不需要进行授权 ...
- CentOS7.5 使用Docker部署Jumpserver
1.环境准备 # 查看系统版本 $ cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) # 查看内核版本 $ uname -a L ...
- 一文回顾Reids五大对象(数据类型)
Redis 是一个高性能的分布式内存型数据库,在国内外各大互联网公司中都有着广泛的使用,即使是一些非互联网公司中也有着非常重要的适用场景,所以对 Redis 的掌握也成为后端工程师必备的基础技能,在面 ...