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; //定义降序排序(从大到小 ...
随机推荐
- 牛客OI赛制测试赛2 C 数组下标
链接:https://www.nowcoder.com/acm/contest/185/C来源:牛客网 题目描述 给出一个数列 A,求出一个数列B. 其中Bi 表示 数列A中 Ai 右边第一个比 ...
- linux破解root登录密码,并重置
重启系统后按'e'键,进入编辑模式,在'UTF -8'后空格输入'rd.break'后,按快捷键'Ctrl+X'进入新界面进行编辑,代码如下: switch_root:/# mount -o remo ...
- JavaScript中函数的调用
JavaScript中函数的调用 制作人:全心全意 在JavaScript中,函数定义后并不会自动执行,要执行一个函数需要在特定的位置调用该函数,调用函数需要创建调用语句,调用语句包含函数名称和参数. ...
- 宝塔nginx配置
虚拟机配置 server { listen 80; server_name mayibang.co *.mayibang.co; index index.php index.html index.ht ...
- 使用scrapy爬取suning
# -*- coding: utf-8 -*- import scrapy from copy import deepcopy class SuSpider(scrapy.Spider): name ...
- python_OS 模块
os模块 用于提供系统级别的操作 os.getcwd() # 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") # 改变当前脚本工作目 ...
- Ubuntu 16.04安装JDK7/JDK8的两种方式
ubuntu 安装jdk 的两种方式:1:通过ppa(源) 方式安装. 2:通过官网下载安装包安装. 这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级 使用ppa ...
- Leetcode 227.基本计算器II
基本计算器II 实现一个基本的计算器来计算一个简单的字符串表达式的值. 字符串表达式仅包含非负整数,+, - ,*,/ 四种运算符和空格 . 整数除法仅保留整数部分. 示例 1: 输入: " ...
- CodeForces 554B--Ohana Cleans Up
B. Ohana Cleans Up time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 杭电ACM省赛集训队选拔赛之热身赛-How Many Tables,并查集模板题~~
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...