Java实现 洛谷 P1583 魔法照片

Java实现 洛谷 P1583 魔法照片_第1张图片

import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] extra = new int[11];
		for(int i = 1; i <= 10; i ++) {
			extra[i] = in.nextInt();
		}
		Person[] person = new Person[n];
		for(int i = 0; i < n; i ++) {
			person[i] = new Person(in.nextInt(), i+1);
		}
		in.close();
		Arrays.sort(person, new Compare());
		for(int i = 0; i < n; i ++) {
			person[i].d = i+1;
			person[i].makeC();
			person[i].weight += extra[person[i].c];
		}
		Arrays.sort(person, new Compare());
		for(int i = 0; i < k; i ++) {
			System.out.print(person[i].id+" ");
		}
		
	}
}
class Person{
	int weight;
	int d;
	int c;
	int id;
	Person(int w,int id){
		this.weight = w;
		this.d = 1;
		this.id = id;
	}
	public void makeC(){
		c = (d-1)%10 + 1;
	}
	
}
class Compare implements Comparator{
	public int compare(Person p1, Person p2) {
		if(p1.weight == p2.weight) return p1.id-p2.id;
		return p2.weight - p1.weight;
	}
}

你可能感兴趣的:(洛谷)