zoukankan      html  css  js  c++  java
  • ECNU 3151 循环打印

    ECNU 3151 循环打印

    链接

    https://acm.ecnu.edu.cn/problem/3151

    题目

    单点时限: 2.0 sec

    内存限制: 256 MB

    以正整数 , 和 作为输入,其中 , 且 。假定数 是环形排列的,编写一个程序,从数 开始,按顺时针方向以 为步长打印数,在打印某个数时,应以从环中删除该数,这样的过程一直进行到环空为止。例如,当 ,, 时,我们得到的输出序列是 3,6,9,2,7,1,8,5,10,4。

    输入格式
    第一行三个整数:, , 以空格分开。

    输出格式
    一行 个数,以空格分开。

    样例
    input
    10 1 3
    output
    3 6 9 2 7 1 8 5 10 4
    提示
    数字间以空格分开,最后一个数字后面没有空格。

    思路

    这边偷了懒,直接用ArrayList,注意检测数组剩余长度。

    代码

    public static void fun() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int t = 0; t < n; t++) {
          list.add(t + 1);
        }
        int s = i;
        while (!list.isEmpty()) {
          s = s + k - 1;
          while (s > list.size()) {
            s = s - list.size();
          }
          int g = list.get(s - 1);
    
          list.remove(s - 1);
          System.out.print(g + " ");
        }
      }
    
  • 相关阅读:
    P1280 尼克的任务
    P2286 [HNOI2004]宠物收养场
    筛法求素数
    拓扑排序
    观光旅游
    [USACO09OCT]热浪Heat Wave
    Java环境变量配置
    git 常用命令
    mysql-5.7安装、配置
    maven-java包管理工具-01
  • 原文地址:https://www.cnblogs.com/blogxjc/p/14358696.html
Copyright © 2011-2022 走看看