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
  1. 3 6 4
  2. 2 2.5 5 1 3 4
  3. 5 1 3.5 2 2 2
  4. 1 1 1 1 1 10
  5. 3 3 2
  6. 1 2 3
  7. 2 3 1
  8. 3 1 2
 
Sample Output
  1. 6 5 3 1
  2. 2 1
 
Author
CHEN, Yue
 
Source
气的我头疼。丫的蛋,尽管是传说中的简单题,题目一边看懂,解法明白。悲剧在好不easy写完后,超时,栈溢出……超时……溢出……wa将近三十次。最后用了结构,跟可悲的是也他妈超时,更可笑的是结构排序解法程序改为 c写法后 立刻通过。虽说笨死 也不能这样欺负人 时间太多浪费了,但还是感觉学到不少东西;
看看这几种解法:
第一种:开三个数组:一个保存n个人的m个数据,一个保存m个求和 数据。还有一个记录前k个支持度高的方案序号。并排完后降序输出;
另外一种:和第一种基本一样 ,仅仅是第三个数组不是用值来记录序号,而是用数组下标。
第三种:前两种,写着写着就发现序号和每一个方案支持度总和是关联的。结构更方便。
 
一:
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<string.h>
  4. const int M=100;
  5. using namespace std;
  6. bool cmp(int a,int b)
  7. {
  8. return a>b;
  9. }
  10. int main()
  11. {
  12. double ls[M][M];
  13. double gq[M];
  14. int flag[M];
  15. int n,m,k,i,j,T;
  16. while(scanf("%d%d%d",&n,&m,&k))
  17. {
  18. int x=0;
  19. memset(gq,0,sizeof(gq));
  20. memset(ls,0,sizeof(ls));
  21. memset(flag,0,sizeof(flag));
  22. for( i=0;i<n;i++)
  23. for(j=0;j<m;j++)
  24. {
  25. scanf("%lf",&ls[i][j]);
  26. gq[j]+=ls[i][j];
  27. }
  28. while(k--)
  29. {
  30. int max=-1;
  31. for(int t=0;t<m;t++)
  32. {
  33. if(gq[t]>max)
  34. {
  35. max=gq[t];
  36. T =t;
  37. }
  38. }
  39. gq[T]=-1;
  40. flag[x++]=T+1;
  41. }
  42. sort(flag,flag+x,cmp);
  43.  
  44. for(int p=0;p<x-1;p++)
  45. printf("%d ",flag[p]);
  46. printf("%d\n",flag[x-1]);
  47. }
  48. return 0;
  49. }

第二:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<string.h>
  4.  
  5. const int M=10000;
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. double ls[M][M];
  11. double gq[M];
  12. int flag[M];
  13. int n,m,k,i,j,T;
  14. while(scanf("%d%d%d",&n,&m,&k))
  15. {
  16. int x=0,I=k;
  17. memset(gq,0,sizeof(gq));
  18. memset(ls,0,sizeof(ls));
  19. memset(flag,0,sizeof(flag));
  20. for( i=0;i<n;i++)
  21. for(j=0;j<m;j++)
  22. {
  23. scanf("%lf",&ls[i][j]);
  24. gq[j]+=ls[i][j];
  25. }
  26. while(k--)
  27. {
  28. int max=-1;
  29. for(int t=0;t<m;t++)
  30. {
  31. if(gq[t]>max)
  32. {
  33. max=gq[t];
  34. T =t;
  35. }
  36. }
  37. gq[T]=-1;
  38. flag[T]=1;
  39. }
  40.  
  41. for(int p=m-1;p>=0;p--)
  42.  
  43. {
  44. if(flag[p]==1)
  45. {
  46. x++;
  47.  
  48. if(x==I)
  49. {
  50. printf("%d\n",p+1);
  51.  
  52. break;
  53. }
  54.  
  55. else
  56.  
  57. printf("%d ",p+1);
  58. }
  59. }
  60. }
  61. return 0;
  62. }

第三:AC代码:

  1. #include<cmath>
  2. #include<iostream>
  3. using namespace std;
  4. #include<algorithm>
  5. #include<string.h>
  6. const int N=10005;
  7. struct ls
  8. {
  9. int k;
  10. double sum;
  11. }gq[N];
  12.  
  13. bool cmp1(ls a,ls b)
  14. {
  15.  
  16. return a.sum>b.sum;
  17.  
  18. }
  19. bool cmp2(ls a,ls b)
  20. {
  21. return a.k>b.k;
  22. }
  23.  
  24. int main()
  25. {
  26. int n,m,k,i;
  27. double re;
  28. while(~scanf("%d%d%d",&n,&m,&k))
  29. {
  30. for(i=0;i<m;i++)
  31. {
  32. gq[i].k=i;
  33. gq[i].sum=0.0;
  34. }
  35. for(int j=0;j<n;j++)
  36. for(int t=0;t<m;t++)
  37. {
  38. scanf("%lf",&re);
  39. gq[t].sum+=re;
  40.  
  41. }
  42.  
  43. sort(gq,gq+m,cmp1);
  44. sort(gq,gq+k,cmp2);
  45. for(int w=0;w<k-1;w++)
  46. printf("%d ",gq[w].k+1);
  47. printf("%d\n",gq[k-1].k+1);
  48. }
  49. return 0;
  50. }

杭电 HDU 1031 Design T-Shirt的更多相关文章

  1. 杭电 HDU ACM 2795 Billboard(线段树伪装版)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. HDU 1031 Design T-Shirt

    http://acm.hdu.edu.cn/showproblem.php?pid=1031 题意 :n个人,每个人对m件衣服打分,每个人对第 i 件衣服的打分要加起来,选取和前 k 高的输出他们的编 ...

  3. 杭电 HDU 4608 I-number

    http://acm.hdu.edu.cn/showproblem.php?pid=4608 听说这个题是比赛的签到题......无语..... 问题:给你一个数x,求比它大的数y. y的要求: 1. ...

  4. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

  5. 杭电 HDU 1242 Rescue

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...

  6. HDU 1031.Design T-Shirt【结构体二次排序】【8月21】

    Design T-Shirt Problem Description Soon after he decided to design a T-shirt for our Algorithm Board ...

  7. ACM 杭电HDU 2084 数塔 [解题报告]

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  8. 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)

    欢迎"热爱编程"的高考少年--报考杭州电子科技大学计算机学院 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memor ...

  9. 杭电 HDU ACM Milk

    Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. BNUOJ 52517 Another Server

    网络流. 似乎有别的做法,没想. #include<bits/stdc++.h> using namespace std; + ; const int INF = 0x7FFFFFFF; ...

  2. Docker入门到实战

    1.系统要求 Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10. CentOS 7满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存 ...

  3. ARP监测工具Arpwatch

    ARP监测工具Arpwatch   ARP协议是网络的基础协议.基于ARP协议的ARP攻击是局域网最为常见和有效的攻击方式.ARP攻击可以通过发送伪造的ARP包实施欺骗,实现各种中间人攻击.Arpwa ...

  4. HDU 1880 简单Hash

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1880] 中文题面,题意很简单: 题解: 把每个 魔咒 和 对应的功能分别Hash,然后分别映射到ma ...

  5. 【20181027T2】易水决【贪心+堆】

    原题:loj6035 [错解] 全肝T1了没怎么想 [正解] 一眼贪心 先考虑\(b_i=0\)怎么做 可以模拟一个正常人的思维 开一个堆,记录每个任务需要的时间(包括等待),每次从中取出一个任务,表 ...

  6. 【递推】hdu5927 Auxiliary Set

    题意:给你一棵树.q次询问,每次给你一些非关键点,其他的点都是关键点,让你输出树中既不是关键点,也不是关键点的lca的点的数量. 对每次询问的非关键点按照深度从深到浅排序,依次处理,最开始每个点受到的 ...

  7. 树形DP+(分组背包||二叉树,一般树,森林之间的转换)codevs 1378 选课

    codevs 1378 选课 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond  题目描述 Description 学校实行学分制.每门的必修课都有固定的学分 ...

  8. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  9. Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题

    Tavas and Karafs Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...

  10. MongoDB基础学习(一) MongoDB概念解析

    .基础概念 SQL术语/概念 MongoDB术语/概念 说明 database database 数据库 table collection 数据表/集合 row document 数据记录行/文档 c ...