题意理解
首先单看数据范围,我觉得会有一个高精度的问题,不过我用的是Java,应该不要担心精度,但是可能需要担心一下时间。我先想一想奖赏最多的大臣获得金币最多的情况应该怎么搞。首先,最多的人获得奖励最大时应该是在最后面的。假设他站在中间能获得最多的奖励,那么他往后挪就可以获得更多的金币。也就是说,我们假设排队后
n
个人的左右手数字分布是
据说很多cpp选手遇到了很多问题,但是我要说的是,Java在高精度问题上真的有优势,我又一次1A了。而且也没花很长时间,因为这份代码确实没有几行。
代码
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
class People implements Comparable {
int left;
int right;
BigInteger money;
@Override
public int compareTo(Object o) {
People people = (People)o;
return this.left * this.right - people.left * people.right;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
BigInteger left = scanner.nextBigInteger();
BigInteger right = scanner.nextBigInteger();
People[] people = new People[n];
for(int i = 0; i < n; i++) {
people[i] = new People();
people[i].left = scanner.nextInt();
people[i].right = scanner.nextInt();
}
scanner.close();
Arrays.sort(people);
for(int i = 0; i < n; i++) {
people[i].money = left.divide(new BigInteger(String.valueOf(people[i].right)));
left = left.multiply(new BigInteger(String.valueOf(people[i].left)));
}
BigInteger max = BigInteger.ZERO;
for(int i = 0; i < n; i++) {
if(people[i].money.compareTo(max) > 0) {
max = people[i].money;
}
}
System.out.println(max);
}
}
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理