java后端
就出了俩道。。。 也只记得大概
- 第一题:做健美操,0,1,休息
- 第二题:比赛,小美被小团嘲讽 AC
小美有n场考试 每场考试时间为m 小美每一场考试所需要的时间为ai
求小美ai和aj(下一场考试用的时间)时间小于m的组合数
测试用例:
3 4
1 2 3
public static void main(String[] args) {
int m = 0, n = 0, c = 0;
int sum = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
long [] arr = new long[n];
while (c < n) {
arr[c] = sc.nextInt();
c++;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if ((arr[i] + arr[j]) <= m) {
sum++;
}
}
}
System.out.println(sum);
}
- 第三题:买礼物 AC
小美给n个朋友买礼物 商店共m个商品 每个朋友要买ai个礼物 每个商品价值为aj 第i个朋友的商品价值不能低于ak
一个朋友不能收到相同的礼物 不同的朋友可以收到相同的礼物
测试用例:
3 5
2 3 3
100 200 300 400 500
200 300 400
public static void main(String[] args) {
int m = 0, n = 0, c = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
int[] toFirArr = new int[n];
int[] shopArr = new int[m];
int[] flag = new int[m];
int[] value = new int[n];
int sum;
while (c < n) {
toFirArr[c] = sc.nextInt();
c++;
}
c = 0;
while (c < m) {
shopArr[c] = sc.nextInt();
c++;
}
c = 0;
while (c < n) {
value[c] = sc.nextInt();
c++;
}
Arrays.stream(shopArr).sorted();
for (int i = 0; i < n; i++) {
sum = 0;
c = 0;
for(int e = 0; e <m;e++){
flag[e] = 0;
}
for (int j = 0; j < m; j++) {
if (shopArr[j] >= value[i] && c < toFirArr[i]) {
flag[c] = shopArr[j];
c++;
}
}
if(c < toFirArr[i]) {
System.out.print(-1 + " ");
}
else {
for(int k = 0; k < toFirArr[i]; k++) {
sum = sum + flag[k];
}
System.out.print(sum + " ");
}
}
}
- 第四题:逛公园看美景(动态规划)
- 第五题:平衡树好像是