• 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;
    	}
    }
    
  • 相关阅读:
    Unity模型导入导出
    3D知识补充
    Unity. Navigation和寻路
    Unity坐标系
    Unity材质
    Unity摄像机
    Unity光照
    Unity资源管理与更新
    Unity垃圾回收
    intellij idea 的全局搜索快捷键方法
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076680.html
Copyright © 2020-2023  润新知