zoukankan      html  css  js  c++  java
  • LightOJ 1179

    链接:http://www.lightoj.com/volume_showproblem.php?problem=1179

    给你一个n个人的圈  每次取出第m个人  问最后一个人是多少号  利用递归直接有每次出来的人

        for(int i = 2; i <= n; i++)  ///这是for循环的求法
                last = (last + k) % i;  
            printf("Case %d: %d
    ", kcase++, last+1);  
    #include<cstdio>///还是喜欢递归
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<math.h>
    #include<string>
    #include<map>
    #include<vector>
    using namespace std;
    #define LL long long
    #define N 100006
    int Q(int n,int m,int v)
    {
        if(v==1) return (n+m-1)%n;
        else return (Q(n-1,m,v-1)+m)%n;
    }
    int main()
    {
        int T,t=1;
        scanf("%d",&T);
        while(T--)
        {
            int n,m;
            scanf("%d%d",&n,&m);//后一个n便是第n次取出的人 可以是任意数字
            printf("Case %d: %d
    ",t++,Q(n,m,n)+1);
        }
        return 0;
    }
  • 相关阅读:
    jsp实现登陆功能小实验
    netty
    shiro
    mybatis
    spring MVC
    spring
    集合框架面试题
    Redis面试题
    Dubbo面试题汇总
    阿里面试题
  • 原文地址:https://www.cnblogs.com/a719525932/p/7682060.html
Copyright © 2011-2022 走看看