美文网首页
CCF201712-2:游戏(JAVA版)

CCF201712-2:游戏(JAVA版)

作者: 巨鹿lx | 来源:发表于2020-03-18 21:55 被阅读0次
    import java.util.Scanner;
    
    public class Main{
        static int N = 1010;
        static int a[] = new int[N];
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            int size = n,cnt = 1,idx = 0;
            while(size>1||a[idx]==1) {//让循环停在未淘汰编号的位置
                if(a[idx]!=1) {//未淘汰
                    if(cnt%k==0||cnt%10==k) {//判断是否满足淘汰规则
                        a[idx] = 1;
                        size--;
                    }
                    cnt++;//有人报数 计数+1
                }
                idx = (idx+1)%n;//每次循环后移一位编号
            }
            System.out.println(idx+1);
        }
    }
    

    相关文章

      网友评论

          本文标题:CCF201712-2:游戏(JAVA版)

          本文链接:https://www.haomeiwen.com/subject/gclhyhtx.html