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. 交叉编译OpenCV的教程——基于aarch64-linux-gnu的交叉编译器

    1.获取OpenCV3.3.1的源码 地址:https://pan.baidu.com/s/1lnKDThiWg-2QDXNEzVAqrA 提取码:vmn4 2.解压源码包 命令:unzip open ...

  2. 文艺平衡树(splay模板)

    题干:splay模板,要求维护区间反转. splay是一种码量小于treap,但支持排名,前驱后继等treap可求的东西,也支持区间反转的平衡树. 但是有两个坏处: 1.splay常数远远大于trea ...

  3. [LOJ] #2363「NOIP2016」愤怒的小鸟

    精度卡了一个点,别人自带大常数,我自带大浮点误差qwq. 听了好几遍,一直没动手写一写. f[S]表示S集合中的猪被打死的最少抛物线数,转移时考虑枚举两个点,最低位的0为第一个点,枚举第二个点,构造一 ...

  4. LINUX:关于Redis集群的节点分配

    文章来源:http://www.cnblogs.com/hello-tl/p/7808268.html 根据上述  Redis集群搭建:http://www.cnblogs.com/hello-tl/ ...

  5. 关于linux安装kettle的总结

    一.部署准备 1.1 JDK安装配置 命令行键入“cd /etc”进入etc目录 命令行键入“vi profile”打开profile文件 敲击键盘ctrl+F到文件末尾 在末尾处,即第一个~的地方, ...

  6. Images for Journals

    Images for publication Table of Contents 1. Images for publication 1.1. image format : vector image ...

  7. pycharm配置git--图文教程

    1.     下载git客户端 2.     File->Default Setting-> Version Control->Git 3.     Path to Git exec ...

  8. Flask--Config研究

    导入Flask框架后,在项目跟目录下面会有一个Config.py 文件,里面的默认内容为: class Config(object): pass 可以这Config 类里面定义变量和其他对象 如: c ...

  9. CodeForces 632A

    A - Grandma Laura and Apples Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  10. C 题 KMP中next[]问题

    题目大意: 找到能够进行字符串匹配的前缀 这题只要一直求next,直到next为0停止,记得答案是总长减去next的长度 #include <iostream> #include < ...