hdoj 1789

来源:互联网 发布:三个字网络流行语 编辑:程序博客网 时间:2024/06/08 16:13

Sample Input
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
题目链接
这题的数据读入是主要问题   先把日期读完 然后读分数
import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;public class Main {public static void main(String[] args) {new Main().run();}public void run() {Scanner in = new Scanner(System.in);int t = in.nextInt();while(t-- > 0) {int n = in.nextInt();ArrayList<Node> list = new ArrayList<>();boolean []vis = new boolean[10000];//这个要开大点 和 n不是一回事for(int i = 0; i < n; i++ ) {//@1注意这些数据一定要分开读  不能直接new Node(d,s);int d = in.nextInt();//因为题目是先读完d后读s的list.add(new Node(d));}for(int i = 0; i < n; i++ ) {//@2int s = in.nextInt();list.get(i).s = s;}Collections.sort(list);//for(Node a:list) {//System.out.println(a.s);//}int sum = 0, j;for(int i = 0; i < n; i++ ) {for(j = list.get(i).d; j > 0; j--) {if(!vis[j]) {vis[j] = true;break;}}if(j == 0) {sum += list.get(i).s;}}System.out.println(sum);}}}class Node implements Comparable<Node>{int d, s;public Node(int d) {//构造函数无类型this.d = d;}@Overridepublic int compareTo(Node o) {if(s == o.s) {return d < o.d ? -1 :1;}else if(s < o.s){return 1;}elsereturn -1;}}

原创粉丝点击