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 ...
随机推荐
- int不可为null引发的 MyBatis做持久层框架,返回值类型要为Integer问题
MyBatis做持久层框架,返回值类型要为Integer MyBatis 做持久层时,之前没注意,有时候为了偷懒使用了int类型做为返回的类型,这样是不可取的,MyBatis做持久层框架,返回值类型要 ...
- JS中this指向问题和改变this指向
首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...
- BadMethodCallException : Call to undefined method App\Models\Article::setContainer()
如果你执行 php artisan db:seed 发生如下错误 说是模型中不存在 静态方法 setContainer()方法,那么你应该检查下你的DatabaseSeeder.php 文件 中的 r ...
- python基本知识点if、while、等等
给予Python的相关知识点: 主要是对于基本语句的相关使用if else while for等先关的应用,以及步骤如下: 尝试编程如下:还有就是对于 import math import rando ...
- 关于Cookie的相关知识点以及使用方法
首先介绍cookie的一些方法 response.addCookie(Cookie cookie)是将一个cookie对象传入客户端. Cookie cookie=new Cookie(String ...
- 2017蓝桥杯取位数(C++B组)
题目: 标题:取数位求1个整数的第k位数字有很多种方法.以下的方法就是一种.// 求x用10进制表示时的数位长度 int len(int x){ if(x<10) return 1; retur ...
- JAVA中的==和equals()的区别
一.先来说说Java的基本数据类型和引用类型 八大基本数据类型:Byte,short,int,long,double,folat,boolean,char,其中占一个字节的是byte,short和ch ...
- Array(数组)对象-->unshift() 方法
1.定义和用法 unshift() 方法可向数组的开头添加一个或更多元素,并返回新的长度. 语法: array.unshift(item1,item2, ..., itemX) 参数:item1,it ...
- scala_spark实践2
参考:jianshu.com/p/9d2d225c1951 监听socket获取数据,代码如下:这里使用nc -lk 9999 在ip为10.121.33.44的机器上发送消息 object Sock ...
- hadoop(六)rsync远程同步|xsync集群分发(完全分布式准备三)|8
前置环境准备:centos7克隆ip|机器名|映射关系|别名配置(hadoop完全分布式准备一)scp命令copy文件和配置(hadoop完全分布式准备二) rsync远程同步工具 优点 rsync主 ...