sdnu oj 1208 玉玉抓兔子

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#define mod 1000000007
using namespace std;
​
typedef long long ll;
const int N = 10006;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-5;
const double pi = acos(-1);
​
int vis[N];
​
int main()
{
    int n, m, i, j;
    scanf("%d%d", &n, &m);
    int pos = 1;              //洞口编号
    if(m >= 1)                // 注意 m == 1 时特判
        vis[1] = 1;
    for(i = 2; i <= m; ++i)
    {
        pos = pos + i;
        if(pos > n)
            pos = (pos-1)%n + 1;       // 看这里,有没有疑惑为什么不是 pos = pos%n 的小可爱?有的话看最后
        vis[pos] = 1;
    }
    int flag = 0;
    for(i = 1; i <= n; ++i)
        if(!vis[i])
        {
            if(flag)
                printf(" %d", i);
            else
                printf("%d", i);
            flag = 1;
        }
    if(!flag)
        printf("-1\n");            //无处可藏(恐怖故事  找到你了)
    return 0;
}
​

是这样啊
在这里插入图片描述

发布了40 篇原创文章 · 获赞 4 · 访问量 1126

猜你喜欢

转载自blog.csdn.net/xiongshuxian2019/article/details/104462992