博弈 HDOJ 4371 Alice and Bob

题目传送门

题意:Alice和 Bob轮流写数字,假设第 i 次的数字是S[i] ,那么第 i+1 次的数字 S[i+1] = S[i] + d[k] 或 S[i] - d[k],条件是 S[i+1] <= n && S[i-1]<S[i+1]

分析:设d[]最小的数字为mn,除此之外设为d,第一次A写了0,第二次B如果写了d,那么A可以写d - mn,确保自己有数直到胜利;如果B第一次写了mn,那么以后的数都只能加mn直到>n,这个很好判断谁胜利。

收获:博弈题想到了就简单了

代码:

#include <cstdio>
#include <algorithm>
using namespace std;

const int M = 1e2 + 10;
int a[M];

int main(void)	{
	int T, cas = 0;
	int n, m;
	scanf ("%d", &T);
	while (T--)	{
		scanf ("%d%d", &n, &m);
		for (int i=1; i<=m; ++i)	scanf ("%d", &a[i]);
		printf ("Case #%d: ", ++cas);
		sort (a+1, a+1+m);
	    if ((n / a[1]) & 1) puts ("Bob");
        else    puts ("Alice");
    }

	return 0;
}

  

时间: 2024-10-15 19:50:42

博弈 HDOJ 4371 Alice and Bob的相关文章

HDU 4371 Alice and Bob

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 691    Accepted Submission(s): 420 Problem Description Alice and Bob are interested in playing games. One day, they invent a game w

博弈问题-Alice与Bob拿牌游戏

Description Bob and Alice play a game, and Bob will play first. Here is the rule of the game: 1) There are N stones at first; 2) Bob and Alice take turns to remove stones. Each time, they can remove p^k stones. p is prime number, such as 2, 3, 5, ...

HDU 4111 Alice and Bob (博弈)

Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1799    Accepted Submission(s): 650 Problem Description Alice and Bob are very smart guys and they like to play all kinds of games i

【HDOJ】3660 Alice and Bob&#39;s Trip

就是一个基本的dfs.可关键问题是c/c++/g++光输入就超时了.还是写java过的,毕竟时限4s.都放弃希望了,没想到还真过了. 1 import java.lang.*; 2 import java.io.*; 3 import java.util.*; 4 5 6 public class Main { 7 8 public static void main(String[] args) throws java.lang.Exception { 9 InputStream inputSt

ZOJ 3529 A Game Between Alice and Bob (分解质因数+Nim博弈)

A Game Between Alice and Bob Time Limit: 5 Seconds      Memory Limit: 262144 KB Alice and Bob play the following game. A series of numbers is written on the blackboard. Alice and Bob take turns choosing one of the numbers, and replace it with one of

XTU 1209 Alice and Bob (博弈)

Alice and Bob Accepted : 174   Submit : 342 Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The famous "Alice and Bob" are playing a game again. So now comes the new problem which need a person smart as you to decide the winne

UVA 1500 - Alice and Bob(博弈)

UVA 1500 - Alice and Bob 题目链接 题意:alice和bob这对狗男女play a game,黑板上有n个数字,每次能把一个数字减1,或者把两个数字合成一个数字,值为两数的和,数字减到0就自动被擦去,最后不能操作的算输,alice先手,问最后谁赢 思路:博弈问题,首先想到一点就很好办了,就是对于非1的所有数,肯定会优先去合并成一个数字的,因为如果当前状态能胜,我优先合并掉,对手不管做什么都无法阻止.然后利用必胜态必败态去进行dp,dp[i][j]记录是有i个1,在非1的堆

ZOJ 3666 Alice and Bob (SG博弈)

题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 题意: 给一个有向图,然后A和B轮流移动棋子,棋子在每一个位置可以重叠,当某人不能走时,输! 问A和B谁赢 方法: 显然每一局游戏都是独立的,对每一局游戏异或即可 每一局游戏的结果可以用SG求,记忆化搜索之 1 int dfs(int x) 2 { 3 if (sg[x] != -1) return sg[x]; 4 bool vis[maxn]; 5 me

ACdream 1112 Alice and Bob(素筛+博弈SG函数)

Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Practice ACdream 1112 Description Here  is Alice and Bob again ! Alice and Bob are playing a game. There are several numbers. First, Alice choose