拼多多 拼越计划 服务端开发 笔经
2020.08.02 晚上 笔试 2h
1)多多的骰子组合
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
if(k == 0) {
System.out.println("paradox");
return;
}
int n = sc.nextInt();
int pos = k, cnt = 0, d;
for(int i = 0; i < n; i++){
d = sc.nextInt();
if(d == pos) {
if(i == n) {
pos = 0;
}
else {
System.out.println("paradox");
return;
}
} else if(d < pos) {
pos -= d;
} else {
pos = d - pos;
cnt++;
}
}
System.out.println(pos + " " + cnt);
}
}
2)多多吃饭
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int t = sc.nextInt();
if(t == 0) {
System.out.println(0);
return;
}
int[][] a = new int[n][2];
int[][] b = new int[m][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
a[i][j] = sc.nextInt();
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 2; j++) {
b[i][j] = sc.nextInt();
}
}
int res = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
if(a[i][1] >= t) {
res = Math.min(res, a[i][0]);
continue;
}
for (int j = 0; j < m; j++) {
if(b[j][1] >= t) {
res = Math.min(res, b[j][0]);
continue;
}
if(a[i][1] + b[j][1] >= t) {
res = Math.min(res, a[i][0] + b[j][0]);
}
}
}
if(res == Integer.MAX_VALUE) {
System.out.println(-1);
return;
}
System.out.println(res);
}
}
第一题100%,第三题50%,第二题不会做,第三题不会做,我好菜。#笔经##校招##拼多多##Java工程师#

