• Java实现 洛谷 P1583 魔法照片


    在这里插入图片描述

    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<Person>{
    	public int compare(Person p1, Person p2) {
    		if(p1.weight == p2.weight) return p1.id-p2.id;
    		return p2.weight - p1.weight;
    	}
    }
    
  • 相关阅读:
    多线程(5)async&await
    多线程(4)Task
    多线程(3)ThreadPool
    多线程(2)Thread
    多线程(1)认识多线程
    泛型
    反射(4)反射性能问题:直接调用vs反射调用
    反射(3)反射应用:一个插件项目
    反射(2)使用反射
    反射(1)认识反射
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076158.html
Copyright © 2020-2023  润新知