zoukankan      html  css  js  c++  java
  • ARC091.f

    Takahashi and Aoki are playing a stone-taking game. Initially, there are NN piles of stones, and the i-th pile contains Aistones and has an associated integer KiKi.

    Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following operation:

    • Choose a pile. If the i-th pile is selected and there are X stones left in the pile, remove some number of stones between 1 and floor(X/Ki) (inclusive) from the pile.

    The player who first becomes unable to perform the operation loses the game. Assuming that both players play optimally, determine the winner of the game. Here,floor(x) represents the largest integer not greater than x

    这道题是我学会SG函数以后做的第一道题。

    可以通过打表发现,SG(x)={x-floor(x/k)-1(x%k!=0),x/k(x%k==0)}

    证明的话,只会感性理解的证明。

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #define N 300
    using namespace std;
    int n,i,a[N],k[N],sg[N],ans,sum;
    int get(int x,int k){
        if (x%k==0) return x/k;
        if (x<k) return 0;
        if ((x-x/k-1)/k!=x/k) return get(x-x/k-1,k);
        int p=x/k,h=(x-p*k)/(p+1);
        return get(x-h*(1+(x/k)),k);
    }
    int main(){
        scanf("%d",&n);
        for (i=1;i<=n;i++)
            scanf("%d%d",&a[i],&k[i]),sg[i]=get(a[i],k[i]),sum=sg[i]^sum;
        if (sum==0)
            printf("Aoki
    ");
        else
            printf("Takahashi
    ");
        return 0;
    }
  • 相关阅读:
    hexo博客安装教程
    MySQL 索引
    linux笔记
    Matab:plot图形操作
    Verilog--DC
    Verilog--二进制编码到格雷码的转换
    Undefined symbol SystemInit (referred from startup_stm32f10x_md.o).
    电源设计
    蓝牙通信
    quartus II的USB Blaster驱动器安装
  • 原文地址:https://www.cnblogs.com/Mohogany/p/13823656.html
Copyright © 2011-2022 走看看