• hdu 3389 Game<阶梯博弈>


    链接:http://acm.hdu.edu.cn/showproblem.php?pid=3389

    题意::1-N带编号的盒子,当编号满足A>B && A非空 && (A + B) % 3 == 0 && (A + B) % 2 == 1则可以从A中取任意石头到B中.谁不能取了谁就输.

    思路: 其本质为阶梯博弈;

      阶梯博弈:博弈在一列阶梯上进行,每个阶梯上放着自然数个点,两个人进行阶梯博弈...每一步则是将一个集体上的若干个点( >=1 )移到前面去,最后没有点可以移动的人输;

    在本题中1,3,4 的状态不能转移到其他状态; 其他每个状态皆可转移; 且位置特定, 如 2->1 , 5->4, 6->3, 7->2 , 8->1 9->6.....

    其本质我们有N级阶梯,现在要在 %3 的余数间转移, 0->0, 1->2, 2->1; 其最后的结果为1, 3, 4; 那么他们的转移的步数的奇偶性也会确定;

    我们只要选择步数为奇数的位置做nim博弈就行了;而可以通过打表归纳证明得出模6为0、2、5的位置移动步数为奇,其余为偶;

    所以~此题得解~

    View Code
     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <string>
     6 #include <stdlib.h>
     7 #include <algorithm>
     8 using namespace std;
     9 typedef long long LL;
    10 const LL Mod= 1e9+7;
    11 int T, N, Ca, x; 
    12 int main( )
    13 {
    14     scanf( "%d", &T );
    15     while( T -- ){
    16         printf( "Case %d: ", ++Ca );
    17         scanf( "%d",&N );
    18         int ans=0;
    19         for( int i=1; i<=N; ++ i ){
    20             scanf( "%d", &x );
    21             if( i%6==0 || i%6==5 || i%6==2 ){
    22                 ans^=x;
    23             }
    24         }
    25         if( ans )puts( "Alice" );
    26         else puts( "Bob" );
    27     }
    28     return 0;
    29 }

  • 相关阅读:
    java Object类是可以接收集合类型的
    java.lang.String中[ "张飞"+1+1 ] 和 [ "张飞"+(1+1) ]
    AFL Fuzz入门
    [转载]linux与grep
    linux下安装clamav
    [转载]Linux连续执行多条命令
    [转载]linux下各文件夹的结构说明及用途介绍
    [转载]linux常用命令
    [转载]Ubuntu 16.04 蓝屏解决方案
    pycharm修改python版本
  • 原文地址:https://www.cnblogs.com/jian1573/p/3050809.html
Copyright © 2020-2023  润新知