zoukankan      html  css  js  c++  java
  • POJ 2484 A Funny Game (博弈)

    题意:Alice 和 Bob 在玩一个无聊的游戏,n个棋子围成一圈,两人轮流从中取走一或两个棋子,不过取两个时必须是连续的棋子。

    棋子取走之后留下空位,相隔空位的棋子不连续。Alice先取,取走最后一个棋子的人赢。如果都采取最优策略,谁会赢?

    析:如果是小于两个,很明显是Alice胜,如果是3个是Bob胜,如果大于 3 个呢,Alice 先拿一两个,然后Bob从中间分开,使得两部分一样,

    那么就一定是Bob胜,因为Alice拿了之后Bob从另一组中拿一样的即可,最后肯定Bob胜。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e3 + 10;
    const int mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int main(){
      while(cin >> n && n)  cout << (n <= 2 ? "Alice" : "Bob") << endl;
      return 0;
    }
    
  • 相关阅读:
    Partition算法及Partition算法用于快速排序
    任意增减文件上传栏
    java版的下雪,大家圣诞快乐
    Java聊天室[长轮询]
    java汉字转拼音以及得到首字母通用方法
    RTree算法Java实现 JSI RTree Library的调用实例 标签:jsi-rtree-library
    JAVA压缩 解压缩zip 并解决linux下中文乱码
    Java 线程转储
    用 Java 抓取优酷、土豆等视频
    Java Web 项目打包脚本
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6605865.html
Copyright © 2011-2022 走看看