Design T-Shirt

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

n个人,m件衣服,输出评价最高的前k件,输出时,评价同样的标号大的先输出。一定要二次排,由于可能所有的评价一样高,仅仅排一次输出就会有错误。

代码例如以下:

#include<cstdio>
#include<algorithm>
using namespace std;
struct ss{
double v;
int x;
};
bool cmp1(ss x,ss y){
if(x.v>y.v) return true;
else return false;
}
bool cmp2(ss x,ss y){
if(x.x>y.x) return true;
else return false;
}
int main(){
int n,m,k;
double t;
ss f[1010];
while(scanf("%d%d%d",&n,&m,&k)==3){
for(int i=0;i<m;i++)
f[i].v=0;
while(n--)
for(int i=0;i<m;i++){
scanf("%lf",&t);
f[i].v+=t;
f[i].x=i+1;
}
sort(f,f+m,cmp1);
sort(f,f+k,cmp2);//二次排。仅仅排前k项
for(int i=0;i<k;i++){
if(i!=0) printf(" ");
printf("%d",f[i].x);
}
printf("\n");
}
return 0;
}

HDU 1031.Design T-Shirt【结构体二次排序】【8月21】的更多相关文章

  1. Problem T: 结构体--学生信息排序

    Problem T: 结构体--学生信息排序 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2219  Solved: 1305[Submit][Sta ...

  2. sort+结构体实现二级排序

    之前介绍的sort函数由于其效率较高,使用较为简单让我用起来那叫一个爽,今天再写一篇使用sort+结构体实现二级排序的方法. 还是先想个问题吧,比如我想输入5个同学的名字和身高,然后得到他们身高的降序 ...

  3. YTU 2878: 结构体--学生信息排序

    2878: 结构体--学生信息排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 297  解决: 148 题目描述 定义存放一个学生信息的结构体类型,学生信息包括:姓名,学号,性别,院 ...

  4. c动态分配结构体二维数组

    这个问题我纠结了蛮久了,因为前面一直忙(自己也懒了点),所以没有能好好研究这个.希望这篇文章能够帮助你们. #include <stdio.h> #include <stdlib.h ...

  5. 使用qsort对结构体的数据排序

    1007 DNA 排序 题目大意: 序列“未排序程度”的一个计算方式是元素乱序的元素对个数.例如:在单词序列“DAABEC'”中,因为D大于右边四个单词,E大于C,所以计算结果为5.这种计算方法称为序 ...

  6. sort();对结构体数组的排序

    sort(); 位于C++ 头文件 #include<algorithm>中 数组排序(从小到大,从大到小) 结构体排序(数字参数从大到小...字符串为参数 字典序....) 代码示例:( ...

  7. PAT A1075 PAT Judge (25 分)——结构体初始化,排序

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  8. c++结构体双关键字排序

    #include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...

  9. 结构体的sort排序

    结构体用sort快排的方法 struct node{ int k,s; }p[]; bool cmp1(node x,node y){ return x.s>y.s; //定义降序排序(从大到小 ...

随机推荐

  1. 「 Luogu P2420 」 让我们异或吧

    # 解题思路 两点之间的路径的话一定经过它们两个 LCA,这一点已经是显而易见的,那么再来看看异或的性质. $$a\ xor\ b\ xor\ b = a\\ a\ xor\ a=0\\ a\ xor ...

  2. tomcat创建用户

    进入manager App时需要用户名+密码 输入错误时会出现页面如下: ​ 根据提示去服务器中找到tomcat目录下的tomcat-user.xml文件 在指定位置添加语句 <user use ...

  3. linux常用过滤日志命令

    #过滤nginx访问日志awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr -k1 | head -n 10 ...

  4. 条款26:尽可能延后变量定义式的出现时间(Postpone variable definitions as long as possible)

    NOTE : 1.尽可能延后变量定义式的出现时间.这样做可增加程序的清晰度并改善程序效率.

  5. 第一章:systemverilog简介

    1.为何要学systemverilog ..... 2.systemverilog起源 ..... 3.systemverilog标准历程 systemverilog3.0 for 综合 system ...

  6. 《算法导论》 — Chapter 7 快速排序

    序 快速排序(QuickSort)也是一种排序算法,对包含n个数组的输入数组,最坏情况运行时间为O(n^2).虽然这个最坏情况运行时间比较差,但是快速排序通常是用于排序的最佳实用选择,这是因为其平均性 ...

  7. 【HIHOCODER 1037】 数字三角形

    链接 问题描述 小Hi和小Ho在经历了螃蟹先生的任务之后被奖励了一次出国旅游的机会,于是他们来到了大洋彼岸的美国.美国人民的生活非常有意思,经常会有形形色色.奇奇怪怪的活动举办,这不,小Hi和小Ho刚 ...

  8. [第一波模拟\day3\T2]{独立集}(bubble.cpp)

    [问题描述] 有一天,一个名叫顺旺基的程序员从石头里诞生了.又有一天,他学会了冒泡排序和独立集.在一个图里,独立集就是一个点集,满足任意两个点之间没有边.于是他就想把这两个东西结合在一起.众所周知,独 ...

  9. 为什么在属性中设置private set

    引言: 属性的引入来自C#的封装机制,也就是说对象的内部数据不应该由对象实例来直接访问,我们可以使用传统的Get和Set方法,来封装字段,C#为我们提供了语法糖,也就是属性.属性包括get和set,分 ...

  10. 大数据学习——hive函数

    1 内置函数 测试各种内置函数的快捷方法: 1.创建一个dual表 create table dual(id string); 2.load一个文件(一行,一个空格)到dual表 3.select s ...