P1080 国王游戏

题解:首先考虑相邻的两个大臣该如何排列。如果

洛谷P1080 国王游戏(贪心)_洛谷P1080排在洛谷P1080 国王游戏(贪心)_ide_02前面需要满足,显然然后因为交换相邻的两个大臣并不会对整个序列的前后有影响,所以我们可以考虑冒泡排序,以

进行排序,但是明显冒泡太慢了,所以需要快排。最后的枚举一下即可。

import java.util.Scanner;
import java.util.Comparator;
import java.math.BigInteger;
import java.util.Arrays;
class Minister{
private int left,right;

public Minister(int x,int y) {
this.left = x;
this.right = y;
}

public int getLeft() {
return this.left;
}

public int getRight() {
return this.right;
}
}

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Minister[] ministers = new Minister[n + 1];
for(int i = 0; i <= n; ++i) {
ministers[i] = new Minister(in.nextInt(),in.nextInt());
}
Arrays.sort(ministers, 1, n + 1, new Comparator<Minister>() {
@Override
public int compare(Minister o1, Minister o2) {
return o1.getLeft() * o1.getRight() - o2.getLeft() * o2.getRight();
}
});
BigInteger emper = new BigInteger(ministers[0].getLeft() + "");
BigInteger max = BigInteger.ZERO;
for(int i = 1; i <= n; ++i) {
BigInteger t = emper.divide(new BigInteger(ministers[i].getRight() + ""));
if(t.compareTo(max) > 0) {
max = t;
}
emper = emper.multiply(new BigInteger(ministers[i].getLeft() + ""));
}
System.out.println(max);
in.close();
}
}