HDU1031结构体排序
来源:互联网 发布:手机续航测试软件 编辑:程序博客网 时间:2024/05/22 11:02
Design T-Shirt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4402 Accepted Submission(s): 2140
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 42 2.5 5 1 3 45 1 3.5 2 2 21 1 1 1 1 103 3 21 2 32 3 13 1 2
Sample Output
6 5 3 12 1
题意:一开始看到题目,一大片英文,没有耐心往下看,直到今天才AC掉,实在是惭愧,这道题的题意是:有n个人对m种元素做出评分,我们最终要找到前k个评分最高的元素的索引,并且按照非升序的顺序输出。这道题就是一道简单的结构体排序。统计所有的评分,然后排下序,输出即可。千万不要被英文吓倒。
#include<iostream>#include<vector>#include<algorithm>using namespace std;struct node{double Element;int index;node():Element(0.0),index(0){}};bool comp1(const node& x,const node& y){if( x.Element == y.Element )return x.index < y.index;return x.Element > y.Element;}bool comp2(const node& x,const node& y){return x.index > y.index;}vector<node> vec;int main(){int people=0,Element=0,K=0,i=0,j=0;double tmp=0.0;while(cin >> people >> Element >> K){vec.clear();vec.resize(Element);for(i=0; i< people; ++i){for(j=0; j<Element; ++j){cin>>tmp;vec[j].index = j+1;vec[j].Element += tmp;}}sort(vec.begin(),vec.end(),comp1);sort(vec.begin(),vec.begin()+K,comp2);/*for(i=0; i<Element; ++i){cout<<vec[i].Element<<' ';}cout<<endl;*/for(i=0; i<K; ++i){if( i == 0 )cout<<vec[i].index;elsecout<<' '<<vec[i].index;}cout<<endl;}return 0;}
- HDU1031结构体排序
- HDU1031——Design T-Shirt(结构体排序)
- hdu1031
- Design T-Shirt(hdu1031,简单排序)
- HDU1031(模拟)
- 结构体排序,多级排序
- 结构体成员排序
- 结构体数组排序
- 结构体排序
- 结构体学号排序
- 结构体数组排序
- qsort 排序结构体
- 结构体排序
- 结构体数组排序
- 结构体来排序
- Hduoj1070!【结构体排序】
- 结构体排序
- 结构体-heap排序
- C++ 排序函数 sort(),qsort()的用法
- shell中exec 与fork/source的区别
- “&”与“==”的优先级谁更高?
- hdu1568(斐波那契数列通项公式)
- 18.正则表达式
- HDU1031结构体排序
- MySQL 体系结构
- 机房收费系统—报表
- zookeeper安装
- 最新隐藏进程 RING3实现方式:hook ZwQuerySystemInformation 隐藏进程 在XP里测试通过
- SSH环境中如何得到LocalSessionFactoryBean
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- 逆向编程培训(第二课)
- vim的交换文件