网易第三题,本地通过为什么一直是0
import java.util.Scanner;
public class Wangyi32 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = Integer.parseInt(s.nextLine());
while (t > 0) {
int k = s.nextInt();
int m = s.nextInt();
int[] arr = new int[30];
for (int j = 0; j < m; j++) {
int val = s.nextInt();
arr[val - 1] = 1;
}
int res = count2(k, m, arr);
System.out.println(res);
t--;
}
}
private static int count2(int k, int m, int[] arr) {
int days = 0;
for (int index = 0; index < 30 - k; index++) {
int rightIndex = index + k;
boolean flag = true;
int cur = index;
while (cur <= rightIndex) {
if (arr[cur] != 1) {
arr[cur] = 1;
cur++;
} else {
flag = false;
break;
}
}
if (flag) {
days++;
}
}
return days + m;
}
}
#笔试题目##网易#
public class Wangyi32 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = Integer.parseInt(s.nextLine());
while (t > 0) {
int k = s.nextInt();
int m = s.nextInt();
int[] arr = new int[30];
for (int j = 0; j < m; j++) {
int val = s.nextInt();
arr[val - 1] = 1;
}
int res = count2(k, m, arr);
System.out.println(res);
t--;
}
}
private static int count2(int k, int m, int[] arr) {
int days = 0;
for (int index = 0; index < 30 - k; index++) {
int rightIndex = index + k;
boolean flag = true;
int cur = index;
while (cur <= rightIndex) {
if (arr[cur] != 1) {
arr[cur] = 1;
cur++;
} else {
flag = false;
break;
}
}
if (flag) {
days++;
}
}
return days + m;
}
}
#笔试题目##网易#