• 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;
    	}
    }
    
  • 相关阅读:
    shell去重
    JDBC源码解析
    try catch finally
    URL
    域名与IP地址的联系与区别
    C++stack
    C++vector
    单链表常见面试题(C语言实现)
    数据库limit子句
    strcpy和memcpy的区别
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076681.html
Copyright © 2020-2023  润新知