ACdream群赛1112(Alice and Bob)

题意:http://acdream.info/problem?pid=1112

Problem Description

Here  is Alice and Bob again !

Alice and Bob are playing a game. There are several numbers.First, Alice choose a number n.Then he can replace n (n > 1)with one of its positive factor but not itself or he can replace n with a and b.Here a*b =
n and a > 1 and b > 1.For example, Alice can replace 6 with 2 or 3 or (2, 3).But he can’t replace 6 with 6 or (1, 6). But you can replace 6 with 1. After Alice’s turn, it’s Bob’s
turn.Alice and Bob take turns to do so.Who can’t do any replace lose the game.

Alice and Bob are both clever enough. Who is the winner?

解法:很好的博弈题。关键是找准每个数的状态。每个数的状态是每个数的分解后的质数的个数。然后就是获得每个数的状态号可以做到On,就是线性筛素数时候顺便将每个数的最小的质数因子筛出来,从小大大先预处理,然后求F(n)就等于F(n/least[n])+1。获得状态号,sg部分就不多说了。

代码:

/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std;

#define eps 1e-8
#define zero(_) (abs(_)<=eps)
const double pi=acos(-1.0);
typedef long long LL;
const int Max=5000010;
const int INF=1000000007;

int f[300];
bool rem[Max];
int out[Max];
int least[Max];
int p=0;
void init()
{
    for(int i=2; i<Max; i++)
        if(!rem[i])
        {
            for(int j=i*2; j<Max; j+=i)
            {
                if(least[j]==-1)
                    least[j]=i;
                rem[j]=1;
            }
            least[i]=i;
        }
}
int getans(int t)
{
    if(f[t]!=-1)
        return f[t];
    int Rem[1000];
    memset(Rem,0,sizeof Rem);
    Rem[0]=1;
    for(int i=1; i<=t/2; i++)
    {
        Rem[getans(i)]=1;
        Rem[getans(t-i)]=1;
        Rem[getans(t-i)^getans(i)]=1;
    }
    int to=0;
    while(Rem[to])to++;
    return f[t]=to;
}
int F(int n)
{
    if(out[n]!=-1)
        return out[n];
    int ans=F(n/least[n])+1;
    return out[n]=ans;
}
int main()
{
    int n;
    memset(f,-1,sizeof f);
    memset(out,-1,sizeof out);
    memset(least,-1,sizeof least);
    f[1]=1;
    init();
    out[1]=0;
    for(int i=0; i<20; i++)
        F(1<<i);// cout<<i<<" "<<getans(i)<<endl;
    while(scanf("%d",&n)==1)
    {
        int ans=0;
        for(int i=0; i<n; i++)
        {
            int t;
            scanf("%d",&t);
            ans^=getans(F(t));
        }
        if(ans)
            puts("Alice");
        else
            puts("Bob");
    }
    return 0;
}

ACdream群赛1112(Alice and Bob)

时间: 2024-08-07 08:15:17

ACdream群赛1112(Alice and Bob)的相关文章

ACdream 1112 Alice and Bob(素筛+博弈SG函数)

Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Practice ACdream 1112 Description Here  is Alice and Bob again ! Alice and Bob are playing a game. There are several numbers. First, Alice choose

ACdream 1112 Alice and Bob (sg函数的变形+素数筛)

题意:有N个数,Alice 和 Bob 轮流对这些数进行操作,若一个数 n=a*b且a>1,b>1,可以将该数变成 a 和 b 两个数: 或者可以减少为a或b,Alice先,问谁能赢 思路:首先单看对每个数进行除法的操作,我们可以知道其实是在除以每个数的素因子或素因子之间的积 比如 70=2*5*7 我们可以变成 10(2*5)或 14(2*7) 或 35(5*7)或 2 或 5 或 7 或 1 这七种状态 当我们把他们(2,5,7)当作3个石子也就是一堆时,然而实际上我们是将这堆石子进行ni

ACdream 1112 Alice and Bob (博弈&amp;amp;&amp;amp;素数筛选优化)

题目链接:传送门 游戏规则: 没次能够将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也能够将原来的堆的个数变成原来堆的约数y.y!=x.进行最后一次操作的人获胜. 分析: 也是一个去石头的游戏,因此我们仅仅须要将全部情况的sg值异或起来就好了. 我们首先来考虑一堆.设这一堆的个数为x: 那么全部的情况就是 (a1,x/a1), (a2,x/a2),...,(an,x/an);或者(a1),(a2),..,(an). 由于数据量比較大,我们朴

ACdream 1112 Alice and Bob (博弈&amp;&amp;素数筛选优化)

题目链接:传送门 游戏规则: 没次可以将一堆分成两堆 x = a*b (a!=1&&b!=1)x为原来堆的个数,a,b为新堆的个数. 也可以将原来的堆的个数变成原来堆的约数y,y!=x.进行最后一次操作的人获胜. 分析: 也是一个去石头的游戏,因此我们只需要将所有情况的sg值异或起来就好了. 我们首先来考虑一堆.设这一堆的个数为x: 那么所有的情况就是 (a1,x/a1), (a2,x/a2),...,(an,x/an);或者(a1),(a2),..,(an). 由于数据量比较大,我们朴素

省赛13 Alice and Bob(组合数学,)

题意:多项式相乘,(a0x+1)(a1x^2+1)(a2x^4+1),问x的m次方的系数是多少,当时没做出来,搜的某大神的博客,好理解. 思路:多列几个式子就能明白规律了: (a0x+1)(a1x^2+1)(a2x^4+1) =a0a1a2x^7+a1a2x^6+a0a2x^5+a2x^4+a0a1x^3+a1x^2+a0x+1 列出来后发现正好该数化为二进制,如果为1,则相乘 7:a0a1a2   即1+2+4 6:a1a2      即2+4 5:a0a2      即1+4 4:a2  

acdream原创群赛(16) --- B - Apple

<传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description Alice and Bob are coming.This time, they are playing with apples. Initially, there are N baskets and M apples. Both bas

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

题目地址:sdut 2608 Alice and Bob Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*....

ACdream原创群赛__15

这场感觉题目确实还算可以,不过,说好的每题10s效果上却不理想.这个时限还算比较紧.因为时间不是按绝对的多出几秒来计算,而是几倍来计算的. 比赛做的不好,后面又去做了一下. A:典型的数位DP,一直坑在这里. E:求f(f(f(n)))%p.f()表示斐波那契数.关于求斐波那契数模的循环节是有特定的数学定理和方法的.我也不知道,但是看了结论之后自己会实现了.首先,把p因数分解,ai^pi,显然最终的循环节就等于这些单独因子计算循环节的lcm.同时ai^pi的循环节又是G(ai)*ai^(pi-1

ACdream原创群赛(13)のwuyiqi退役专场 H Salmon And Cat

H 首先是要姿势正确! 注意完美数的生成机: 2+2a+2b+ab ab都是完美数 假设生成完美数c c = 2 + 2a + 2b + ab c + 2 = ab+2a+2b+4 c + 2 = (a + 2)(b + 2) 然后一开始只有两个完美数1和3. 所以所有的完美数只有质因数分解之后都是类似于 N = (3 ^ x) * (5 ^ y) 但是5不是完美数. 然后就没事了... /**** *COPYRIGHT NOTICE *Copyright (c) 2014 *All right