【原创】HDU 4642 Fliping game

HDU 4642 Fliping game

Description

Alice and Bob are playing a kind of special game on an N ∗ M N*M NM board ( N N N rows, M M M columns). At the beginning, there are N ∗ M N*M NM coins in this board with one in each grid and every coin may be upward or downward freely. Then they take turns to choose a rectangle ( x 1 , y 1 ) − ( n , m ) ( 1 ≤ x , 1 ≤ n , 1 ≤ y , 1 ≤ m ) (x _1, y_1)-(n, m) (1 ≤ x ,1≤n, 1≤y,1≤m) (x1,y1)(n,m)(1x,1n,1y,1m) and flips all the coins (upward to downward, downward to upward) in it (i.e. flip all positions (x, y) where x_1≤x≤n, y_1≤y≤m)). The only restriction is that the top-left corner (i.e. ( x 1 , y 1 ) (x_1, y_1) (x1,y1)) must be changing from upward to downward. The game ends when all coins are downward, and the one who cannot play in his (her) turns loses the game. Here’s the problem: Who will win the game if both use the best strategy? You can assume that Alice always goes first.

Input

The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case starts with two integers N and M indicate the size of the board. Then goes N line, each line with M integers shows the state of each coin, 1 &lt; = N , M &lt; = 100 1&lt;=N,M&lt;=100 1<=N,M<=100. 0 means that this coin is downward in the initial, 1 means that this coin is upward in the initial.

Output

For each case, output the winner’s name, either Alice or Bob.

Sample Input

2
2 2
1 1
1 1
3 3
0 0 0
0 0 0
0 0 0

Sample Output

Alice
Bob

题意

Alice和Bob博弈。每人每次可以选一个点,然后将以这个点为左上角,(n,m)为右下角的矩形里的所有硬币翻转。如果所有硬币都是背面朝上,那么你就动不了了,动不了你就输了。

分析

第一眼没看到矩形,以为是翻对角线,于是说出了“这题就是把对每条对角线跑SG函数再异或起来”这样的话,旁边的同学都拿诧异的眼神看着我。

这道题……
因为每次都会翻到(n,m)这个点,所以刚开始Alice出手的时候它是背面朝上,那么每次Alice出手的时候都是背面朝上,Alice输定了。

结束了。

想起了一道题,最初我在数学杂志上看到过,后来在matrix67学长的博客又看到过一次的一道趣题。
一个盒子里面有50个白球,51个黑球,地面上有很多球。每次从盒子里随机取出两个球丢在地上,如果这两球是同种颜色,就捡起一个黑球丢回去;否则捡起一颗白球丢回去。问最后那颗球是黑色的概率是多少,是白色的概率又是多少?
发现白球总是减少偶数个,黑球总是减少奇数个(2白=白-2,黑+1 // 2黑=黑-1 // 1黑1白=黑-1),所以最后那个总是黑球。

代码

这道题的代码。

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int T,n,m,z;
int main()
{
	scanf("%d",&T);
	while(T--) 
	{
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n*m;i++) scanf("%d",&z);
		puts(z?"Alice":"Bob");
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值