尽管难度比较简单,但也需要准备充分呐。
题型分布:
选择题 20 * 2 + 编程题 20 * 3
选择题
1. java se 大概 十道题
2. 编译原理(不多不难,就是做不出来)、计算机基础、(离散数学???)
编程题 第一题
/**
* 这天,阳阳和他的小伙伴们一起玩游戏!
* 他们总共有n个人,排成一圈,然后从第一个人开始依次报数,1,2,3,....,
* 报到m的人退出游戏,然后从下一个人开始重新从1报数,重复这个过程,直到只剩下一个人时,此人就是游戏的获胜者
*/
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
scanner.close();
solution(n, m);
}
private static void solution(int n, int m) {
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = i;
}
int count = 0;
int totalCount = 0;
boolean flag = true;
int begin = 0;
List<Integer> list = new LinkedList<>();
while (flag) {
for (int i = begin; i < array.length; i++) {
if (count < m && array[i] != -1) {
++count;
if (count == m) {
count = 0;
++totalCount;
array[i] = -1;
list.add(i+1);
continue;
}
continue;
}
if (count == 0 && array[i] != -1) {
begin = i;
}
if (totalCount == n) {
flag = false;
break;
}
}
}
for (int i = 0; i < list.size() - 1; i++) {
System.out.print(list.get(i) + " ");
}
System.out.println();
System.out.print(list.get(list.size() - 1));
}
}
编程题 第三题
使用递归,题目忘记了,有时间再补。。。
import java.util.Scanner;
//第三题
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for (int i = 0; i < T; i++) {
int m = solution(scanner.nextInt());
System.out.println(m - 1);
}
scanner.close();
}
private static int solution(int n) {
// System.out.println("n = " + n);
int count = 0;
if (n == 1) {
count = 1;
return count;
}
if (n > 1 && n % 2 == 0) {
count++;
count += solution(n / 2);
// System.out.println("count : " + count);
}
if (n > 1 && n % 2 != 0) {
count++;
count += solution(n * 3 + 1);
// System.out.println("count : " + count);
}
return count;
}
}