• 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;
    	}
    }
    
  • 相关阅读:
    skill:极角排序
    skill:树的重心
    [CF1091F](New Year and the Mallard Expedition)
    2018九省联考(SHOI2018)
    陷入僵局?
    2333
    雨后天晴
    听说我首次抢到食堂最早的馄饨
    难题做不动
    成绩出来了?
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947068.html
Copyright © 2020-2023  润新知