全部评论
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int[] res = support(n); System.out.println(res[0] + "/" + res[1]); }
} public static int[] support(int n){ int[] res = new int[2]; int count = 1; int rowIndex = 1; int colIndex = 1; boolean flag = true; //标识,表示转方向 if(n == 1){ res[0] = rowIndex; res[1] = colIndex; return res; } while(count != n) { if (rowIndex == 1 && flag) {
colIndex++; count++; flag = false; } while (colIndex != 1 && count != n) {
colIndex--; rowIndex++; count++; } if (colIndex == 1 && !flag) {
rowIndex++; count++; flag = true; } while (rowIndex != 1 && count != n) {
rowIndex--; colIndex++; count++; }
} res[0] = rowIndex; res[1] = colIndex; return res; }
}
你是什么岗的笔试呀兄弟
有点难啊
第一道题找规律,第二道题贪心,第三道题没时间看qaq
有没有人跟我一样算法只对了一个
第一题不难 先算一个等差 再判断下奇偶 做个加法减法就出来了
你有消息了吗,我考完到现在还没任何消息
public class Game { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = 0, m = 0; while (scan.hasNext()) { n = scan.nextInt(); m = scan.nextInt(); int[] peoples = new int[n];
for (int i = 0; i < peoples.length; i++) {
peoples[i] = 0;
}
int[] fails = new int[n];
int c = 0;
int step = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (peoples[step] == 0) {
step++;
if (step >= n) {
step = 0;
}
} else {
j--;
step++;
if (step >= n) {
step = 0;
}
}
}
int tempor = step - 1;
if (tempor < 0) {
tempor = n - 1;
}
fails[c++] = tempor + 1;
peoples[tempor] = 1;
}
for (int i = 0; i < fails.length - 1; i++) {
System.out.print(fails[i] + "\t");
}
System.out.println();
System.out.print(fails[n - 1]);
}
}}
相关推荐
点赞 评论 收藏
分享
01-26 18:45
门头沟学院 Java 点赞 评论 收藏
分享
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
腾讯
| 校招
| 超多精选岗位
点赞 评论 收藏
分享