百度笔试 4月13号 java
我第二题不知道咋回事只过了15%,一开始思路是选增长价格最大的 ,偶数日选两个,大家什么思路?
#百度笔试#
import java.util.Scanner;
public class baidu1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[][] value = new int[n][2];
for (int l = 0; l < n ; l++){
value[l][0] = scan.nextInt();
value[l][1] = scan.nextInt();
}
for (int i=0;i<n;i++){
for (int j=0;j<n-1-i;j++){
if (value[j][1]>value[j+1][1]){
int temp = value[j][1];
value[j][1] = value[j+1][1];
value[j+1][1] = temp;
int tempp = value[j][0];
value[j][0] = value[j+1][0];
value[j+1][0] = tempp;
}
}
}
int sum = 0;
int x = n/3;
int xx = n%3;
int day = x*2+xx;
for (int j =0;j<day;j++){
if (j%2 ==0){
int end = n-1;
if (value[end][1] == 0){
end--;
}
sum = sum + value[end][0]+j*value[end][1];
value[end][1] = 0;
}else {
int end = n-1;
if (value[end][1] == 0){
end--;
}
if (end == 0){
sum = sum + value[end][0]+j*value[end][1];
value[end][1] = 0;
break;
}
if (value[end][0]+j*value[end][1] <= value[end-1][0]+j*value[end-1][1]){
sum = sum + value[end][0]+j*value[end][1];
value[end][1] = 0;
value[end-1][1] = 0;
}else {
sum = sum + value[end-1][0]+j*value[end-1][1];
value[end][1] = 0;
value[end-1][1] = 0;
}
}
}
System.out.println(sum);
}
}
#百度笔试#
OPPO公司福利 1202人发布
