HDOJ Design T-Shirt(Java)
来源:互联网 发布:数据堂众包 编辑:程序博客网 时间:2024/06/05 13:33
Design T-Shirt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5021 Accepted Submission(s): 2436
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 1AC代码:题目就是输出递减的具有满意度总和值最大的矩阵的列下标,矩阵的下标从1开始;主要是注意输出的格式正确;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); double[] value = new double[m+5]; int[] index = new int[m+2]; int maxIndex = -1; int count = 1; int count2 = 0; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ index[j] = -1; value[j] += in.nextDouble(); } } while(count <= k){ double max = -1; for(int i = 1; i<=m; i++){ if(value[i] > max){ max = value[i]; maxIndex = i; } } value[maxIndex] = -1; index[maxIndex] = 1; count++; } for(int i=m; i>=1; i--){ if(index[i] == 1){ count2++; if(count2 == k){ System.out.print(i); System.out.println(); break; }else{ System.out.print(i+" "); } } } } }}
0 0
- HDOJ Design T-Shirt(Java)
- HDOJ 1031-Design T-Shirt(排序)
- hdoj 1031 Design T-Shirt(排序)
- HDOJ 1031 Design T-Shirt
- hdoj 1031 Design T-Shirt
- HDOJ 1031 Design T-Shirt
- HDU1031 Design T-Shirt(java)
- Design T-Shirt(排序)
- Design T-Shirt(sort)
- ACM-一道简单的排序题(HDOJ 1031)Design T-Shirt
- HDoj 1031 Design T-shirt(题目很绕的水题)
- Design T-Shirt(hdu1031,简单排序)
- HDU1031--Design T-Shirt HDU(154)
- Design T-Shirt(贪心算法)
- HDU 1031 Design T-Shirt(水~)
- HDU1031 - Design T-Shirt (水题 模拟)
- Design T-Shirt
- Design T-Shirt
- C#中的转换关键字:explicit、implicit与operator
- Android基础--Service与Activity之间通信的几种方式
- 流程控制---选择结构笔记
- inverse和cascade
- iOS7.1企业应用"无法安装应用程序 因为证书无效"的解决方案
- HDOJ Design T-Shirt(Java)
- 银行业务调度系统
- CArchive::WriteString 处理 Unicode 字符串数据
- Java Socket实战之三 传输对象
- Lucene查询优化
- SQL中的INNER JOIN和JOIN有什么区别
- uboot学习笔记
- Unity Windows 填坑日记之导出篇
- 第一章 对象导论