虽然我没考,还是做了一下 package 搜狐校招; import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class test { public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.in)); int n = in.nextInt(); //输出多少行 int m = in.nextInt(); //给定数组长度 int[] arr = new int[m]; for (int i = 0; i < m; i++) { arr[i] = in.nextInt(); } int[] ansArr = new int[n];//结果数组 int slowPoint = 0; int fastPoint; int index; if (arr[0] == 1) { ansArr[0] = arr[0]; for (int i = 1; i < arr[1] + 1; i++) { ansArr[i] = arr[1]; } fastPoint = ansArr[2]; index = arr[1] +1; slowPoint = (slowPoint + 2) % m; System.out.println(fastPoint); } else { for (int i = 0; i < arr[0]; i++) { ansArr[i] = arr[0]; } index = arr[0]; fastPoint = arr[1]; slowPoint = 1; System.out.println(fastPoint); } int temp = 0; for (int i = index; i < n; i++) { if (temp < ansArr[fastPoint]) { ansArr[i] = arr[slowPoint]; temp++; if (temp == ansArr[fastPoint]) { temp = 0; fastPoint++; slowPoint = (slowPoint + 1) % m; } } } System.out.println(Arrays.toString(ansArr)); } }
点赞 2

相关推荐

12-19 16:52
门头沟学院
点赞 评论 收藏
分享
_mos_:要不是看评论区我都不知道你要找的是数分
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务