zoukankan      html  css  js  c++  java
  • POJ Football Game 【NIMK博弈 && Bash 博弈】

    Football Game

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 451   Accepted: 178

    Description

    Alice and Bob both love football very much, and both of them are vanguards. They are both good at football control. One day after a football match, they play an interesting game, in which they shoot footballs forward the goal directly. There are N footballs in front of the goal, and they play this game in turn. For example, if it is Alice's turn, Alice can choice some footballs (the number of footballs mush equal or less than M) and shoot them forward. Because the footballs' quality is not very good, footballs are not a complete sphere and can only roll integer times of its girth. And because of restriction of the friction and strength of them, they cannot shoot a football farther then L centimeters. Of course, they know the radius of a football is R centimeters. Alice and Bob love this game very much. If both of them have unlimited IQ and precision shooting skill, can you guess who can win the football game? By the way, though Alice is as strong as Bob, Alice is a girl, so she will shoot first.

    Input

    The input consists of several cases, each of which contains two lines. 

    For each test case, the first line contains 4 integers N, M, L and R (1 <= M <= N <= 30, 0 < L < 100000000, 0 < R < 10000), separated by a single space. N is the number of the footballs, M is the maximum number of footballs one player can shot in one turn, L is the maximum distance that a player can shoot, and R is the radius of footballs. 

    The next line contains N numbers, S(1), S(2), ..., S(N) (0 < S(i) < 100000000), which describe the distance between footballs and the goal.

    Output

    For each case output contains one line describing the name of the winner.

    Sample Input

    2 1 30 1
    8 14
    2 1 30 1
    8 12
    2 1 30 1
    8 10
    2 1 30 1
    40 200
    

    Sample Output

    Alice
    Bob
    Bob
    Bob
    

    Source

     
     
    题意概括:
    有 N 个足球每个距离球门 D 远,两人轮流选择小于等于 M 个球射门, 射球最远距离为 L,球的半径为 R (球每次只能移动 周长的整数倍),最后射球者胜,先手赢还是后手赢;
    解题思路:
    首先要求问题进行转换 N 个球相当于 N 堆物品, 由于每个球只能滚动 周长的整数倍,所以可以把 球到球门的距离 离散化(即选多少个物品),而由于射门有最大距离,所以选取范围 小于 K,(单独看单堆即 Bash 博弈)
    接下来考虑 NIM 游戏的变形,普通的 NIM 游戏 每次选取一个堆取若干物品,NIMK 游戏 每次选取 ≤ K 个堆取若干物品。
    结论 同样是异或所有堆数,不过不是 模二异或 而是 模(K+1)异或。奇异局势为必败态。 
     
    AC code:
     1 //#include <bits/stdc++.h>
     2 #include <set>
     3 #include <map>
     4 #include <queue>
     5 #include <cmath>
     6 #include <cstdio>
     7 #include <string>
     8 #include <vector>
     9 #include <cstdlib>
    10 #include <cstring>
    11 #include <iostream>
    12 #include <algorithm>
    13 #define inc(i, j, k) for(int i = j; i <= k; i++)
    14 #define rep(i, j, k) for(int i = j; i < k; i++)
    15 #define F(x) ((x)/3+((x)%3==1?0:tb))
    16 #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
    17 #define INF 0x3f3f3f3f
    18 #define LL long long
    19 #define MEM(i, j) memset(i, j, sizeof(i));
    20 #define gcd(i, j) __gcd(i, j)
    21 using namespace std;
    22 const int MAXN = 1e5+10;
    23 const double PI = acos(-1.0);
    24 int SG[MAXN];
    25 int XOR[MAXN];
    26 int xxx;
    27 int num;
    28 int maxn;
    29 
    30 bool solve(int N, int M)
    31 {
    32     MEM(XOR, 0);
    33     maxn = -1;
    34     inc(i, 1, N){
    35         xxx = SG[i];
    36         num = 0;
    37         while(xxx){
    38             XOR[num]+=xxx&1;
    39             num++;
    40             xxx>>=1;
    41         }
    42         maxn = max(maxn, num);
    43     }
    44     rep(i, 0, maxn){
    45         if(XOR[i]%(M+1)) return true;
    46     }
    47     return false;
    48 }
    49 int N, M, L, R;
    50 int s;
    51 
    52 int main()
    53 {
    54     while(~scanf("%d %d %d %d", &N, &M, &L, &R)){
    55         s = L/(2*PI*R);         //最远的距离
    56         inc(i, 1, N){
    57             scanf("%d", &SG[i]);
    58             SG[i] = SG[i]/(2*PI*R) + 1;   //距离球门的距离
    59             SG[i]%=s+1;                   // Bash博弈
    60         }
    61         if(solve(N, M)) puts("Alice");      //NIMK 博弈
    62         else puts("Bob");
    63     }
    64     return 0;
    65 }
    View Code
     
     
  • 相关阅读:
    多线程 NSThread GCD
    UICollectionView 集合视图用法,自定义Cell
    简单的注册 登录
    数据库sqlite的使用
    沙盒机制 归档 反归档
    图片异步加载 ,KVO
    iOS开发系列--通知与消息机制
    制作iOS Ad-Hoc测试应用
    NT_iOS笔记—判断iPhone6
    iOS开发多线程篇—单例模式(ARC)
  • 原文地址:https://www.cnblogs.com/ymzjj/p/10738340.html
Copyright © 2011-2022 走看看