HDU 1031.Design T-Shirt【结构体二次排序】【8月21】
Design T-Shirt
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.
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.
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.
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
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】的更多相关文章
- Problem T: 结构体--学生信息排序
Problem T: 结构体--学生信息排序 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2219 Solved: 1305[Submit][Sta ...
- sort+结构体实现二级排序
之前介绍的sort函数由于其效率较高,使用较为简单让我用起来那叫一个爽,今天再写一篇使用sort+结构体实现二级排序的方法. 还是先想个问题吧,比如我想输入5个同学的名字和身高,然后得到他们身高的降序 ...
- YTU 2878: 结构体--学生信息排序
2878: 结构体--学生信息排序 时间限制: 1 Sec 内存限制: 128 MB 提交: 297 解决: 148 题目描述 定义存放一个学生信息的结构体类型,学生信息包括:姓名,学号,性别,院 ...
- c动态分配结构体二维数组
这个问题我纠结了蛮久了,因为前面一直忙(自己也懒了点),所以没有能好好研究这个.希望这篇文章能够帮助你们. #include <stdio.h> #include <stdlib.h ...
- 使用qsort对结构体的数据排序
1007 DNA 排序 题目大意: 序列“未排序程度”的一个计算方式是元素乱序的元素对个数.例如:在单词序列“DAABEC'”中,因为D大于右边四个单词,E大于C,所以计算结果为5.这种计算方法称为序 ...
- sort();对结构体数组的排序
sort(); 位于C++ 头文件 #include<algorithm>中 数组排序(从小到大,从大到小) 结构体排序(数字参数从大到小...字符串为参数 字典序....) 代码示例:( ...
- PAT A1075 PAT Judge (25 分)——结构体初始化,排序
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- c++结构体双关键字排序
#include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...
- 结构体的sort排序
结构体用sort快排的方法 struct node{ int k,s; }p[]; bool cmp1(node x,node y){ return x.s>y.s; //定义降序排序(从大到小 ...
随机推荐
- 复制webp图片到word || 微信webp图片不能复制 || 如何复制webp到word
用IE浏览器打开Alt+A 复制直接去word粘贴, 用IE浏览器打开Alt+A 复制直接去word粘贴 用IE浏览器打开Alt+A 复制直接去word粘贴 用IE浏览器打开Alt+A 复制直接去wo ...
- 用python的Requests库模拟http请求
一.先了解几个重要的http请求头或响应头信息 Request Headers: Host: 描述请求将被发送的目的地,包括,且仅仅包括域名和端口号. Origin: 说明请求从哪里发起的,包括,且仅 ...
- mysql中别名(列别名和表别名)
1.介绍 使用MySQL别名来提高查询的可读性.MySQL支持两种别名,称为列别名和表别名. 有时,列的名称是一些表达式,使查询的输出很难理解.要给列一个描述性名称,可以使用列别名.用法: SELEC ...
- LEFT JOIN结果集可能变大。。。。。
SELECT A.*,B.* FROM A LEFT JOIN B ON A.ID = B.ID
- 电源模块PCB设计
电源模块的PCB设计 电源电路是一个电子产品的重要组成部分,电源电路设计的好坏,直接牵连产品性能的好坏.我们电子产品的电源电路主要有线性电源和高频开关电源.从理论上讲,线性电源是用户需要多少电流,输入 ...
- ES6(数据结构)
一.set 用法 set 对数组进行转化 添加重复元素不会生效 (应用:去重复功能)转化过程不会有数据类型的转换 添加.删除.判断是否存在的方法 2. 读取(遍历)的几种方法 二.WeakSet 与S ...
- 用python写自定义模板
模板语法有点像php !/usr/bin/env python """ #demo.py.html <html> <?py include head.p ...
- STM32F407 串口通信实验 视频第27节 个人笔记
前言 第26节也是串口,笔记链接在此:https://www.cnblogs.com/YuQiao0303/p/10019362.html github地址:https://github.com/Yu ...
- 大数据学习——面试用sql——累计报表
create table t_access_times(username string,month string,salary int)row format delimited fields term ...
- 【状压DP】OpenJ_POJ - C17K Lying Island
https://vjudge.net/contest/171652#problem/K [题意] 小岛上有n个人,有些是好人(一定是真话),有些是坏人(可能是真话也可能是假话),现在要判断最多有多少好 ...