Loading

1875 丢手绢 (模拟+打表)

题意就不说了。

不会之前,还是感觉挺难的。

思路:n表示多少人,e表示传的长度,刚开始从1传给n+1~n+n;那么n为多少合适呢?

先是枚举e,e是无上界限的,用一个非常大的数来表示哦。

s表示当前的位置, s+e之后  整个圈all--;而s也要--的;(相对位置是不变的)然后再加e,求余(数学的周期一样)

表示的新位置我们就需要判断了,符合在n+1—n+n就继续,否则枚举下一个e,如果一直跳到新的位置,并且都满足条件

那么,当圈的大小变成n时,说明e是正确的。

怎么样是不是很裸的模拟

ac代码:

#include<cstdio>
int ans[20];
int deal(int x)
{
    for (int i = 1; i <= 1e7; ++i)
    {
        int all = x * 2;
        int s = 0;
        while (all > x)
        {
            s += s == 0 ? 0 : -1;
            s = (s + i) % all;
            if (s <= x&&s != 0)
                break;
            all--;
            if (all == x)
                return i;
        }
    }
}
void init()
{
    ans[1] = 1;
    for (int i = 1; i <= 13; ++i)
        ans[i] = deal(i);
}
int main()
{
    init();
    int n;
    while (scanf("%d", &n), n)  printf("%d\n", ans[n]);

}

 

posted @ 2018-08-16 23:13  青山新雨  阅读(226)  评论(0编辑  收藏  举报