博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电 HDU 1031 Design T-Shirt
阅读量:5905 次
发布时间:2019-06-19

本文共 3687 字,大约阅读时间需要 12 分钟。

Design T-Shirt

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6527    Accepted Submission(s): 3061
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
 
Author
CHEN, Yue
 
Source
气的我头疼。丫的蛋,尽管是传说中的简单题,题目一边看懂,解法明白。悲剧在好不easy写完后,超时,栈溢出……超时……溢出……wa将近三十次。最后用了结构,跟可悲的是也他妈超时,更可笑的是结构排序解法程序改为 c写法后 立刻通过。虽说笨死 也不能这样欺负人 时间太多浪费了,但还是感觉学到不少东西;
看看这几种解法:
第一种:开三个数组:一个保存n个人的m个数据,一个保存m个求和 数据。还有一个记录前k个支持度高的方案序号。并排完后降序输出;
另外一种:和第一种基本一样 ,仅仅是第三个数组不是用值来记录序号,而是用数组下标。
第三种:前两种,写着写着就发现序号和每一个方案支持度总和是关联的。结构更方便。
 
一:
#include
#include
#include
const int M=100;using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ double ls[M][M]; double gq[M]; int flag[M]; int n,m,k,i,j,T; while(scanf("%d%d%d",&n,&m,&k)) { int x=0; memset(gq,0,sizeof(gq)); memset(ls,0,sizeof(ls)); memset(flag,0,sizeof(flag)); for( i=0;i
max) { max=gq[t]; T =t; } } gq[T]=-1; flag[x++]=T+1; } sort(flag,flag+x,cmp); for(int p=0;p
第二:
#include
#include
#include
const int M=10000;using namespace std;int main(){ double ls[M][M]; double gq[M]; int flag[M]; int n,m,k,i,j,T; while(scanf("%d%d%d",&n,&m,&k)) { int x=0,I=k; memset(gq,0,sizeof(gq)); memset(ls,0,sizeof(ls)); memset(flag,0,sizeof(flag)); for( i=0;i
max) { max=gq[t]; T =t; } } gq[T]=-1; flag[T]=1; } for(int p=m-1;p>=0;p--) { if(flag[p]==1) { x++; if(x==I) { printf("%d\n",p+1); break; } else printf("%d ",p+1); } } } return 0;}
第三:AC代码:
#include
#include
using namespace std;#include
#include
const int N=10005;struct ls{ int k; double sum;}gq[N];bool cmp1(ls a,ls b){ return a.sum>b.sum;}bool cmp2(ls a,ls b){ return a.k>b.k;}int main(){ int n,m,k,i; double re; while(~scanf("%d%d%d",&n,&m,&k)) { for(i=0;i

转载地址:http://udcpx.baihongyu.com/

你可能感兴趣的文章
UNIX网络编程读书笔记:TCP输出、UDP输出和SCTP输出
查看>>
扩展 DbUtility (1)
查看>>
iOS开发UI篇—使用picker View控件完成一个简单的选餐应用
查看>>
Hadoop学习笔记系列文章导航
查看>>
SpringMVC中ModelAndView addObject()设置的值jsp取不到的问题
查看>>
Prometheus : 入门
查看>>
使用 PowerShell 创建和修改 ExpressRoute 线路
查看>>
在C#中获取如PHP函数time()一样的时间戳
查看>>
Redis List数据类型
查看>>
大数据项目实践(四)——之Hive配置
查看>>
初学vue2.0-组件-文档理解笔记v1.0
查看>>
上传图片预览
查看>>
lagp,lacp详解
查看>>
LVS之DR模式原理与实践
查看>>
Docker的系统资源限制及验证
查看>>
c++ ios_base register_callback方法使用
查看>>
Java中为什么需要Object类,Object类为什么是所有类的父类
查看>>
angularjs-paste-upload
查看>>
linux基础命令 head
查看>>
objective c:import和include的区别, ""和<>区别
查看>>