//生成Kolakoski序列 import java.util.Scanner; public class Kolakoski { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] num = new int[m]; for (int i = 0; i < m; i++) { num[i] = sc.nextInt(); } sc.close(); int[] arrSequ = new int[n]; int[] arrLen = new int[n]; arrLen[0] = num[0]; int i = 0, k = 0, s = 0, sumLen = 0; outer: while (true) { for (i = 0; i < arrLen.length; i++) { for (int j = 0; j < arrLen[i]; j++) { arrSequ[s++] = num[k % 4]; if (s >= n) break outer; } sumLen = sumLen + arrLen[i]; ++k; for (int j = sumLen - arrLen[i]; j < sumLen; j++) arrLen[j] = arrSequ[j]; } } for (int j = 0; j < n; j++) { System.out.print(arrSequ[j]+" "); } } }
点赞 评论

相关推荐

10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
牛客网
牛客企业服务