CodeForces 69D Dot (博弈+记忆化)

Description

Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code
name "dot" with the following rules:

  • On the checkered paper a coordinate system is drawn. A dot is initially put in the position
    (x,?y).
  • A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line
    y?=?x.
  • Anton and Dasha take turns. Anton goes first.
  • The player after whose move the distance from the dot to the coordinates‘ origin exceeds
    d, loses.

Help them to determine the winner.

Input

The first line of the input file contains 4 integers x,
y, n,
d (?-?200?≤?x,?y?≤?200,?1?≤?d?≤?200,?1?≤?n?≤?20) — the initial coordinates of the dot, the distance
d and the number of vectors. It is guaranteed that the initial dot is at the distance less than
d from the origin of the coordinates. The following
n lines each contain two non-negative numbers
xi and
yi (0?≤?xi,?yi?≤?200) — the coordinates of the i-th
vector. It is guaranteed that all the vectors are nonzero and different.

Output

You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.

Sample Input

Input

0 0 2 3
1 1
1 2

Output

Anton

Input

0 0 2 4
1 1
1 2

Output

Dasha

题意:有一个移点的游戏,Anton先移,有n个移动选择,也可以沿着直线y=x对称且只能一次,如果有人先移动到距离原点>=d的时候为输

思路:对于直线y=x对称的情况,没有考虑,因为如果有人下一步一定移到>=d的位置的话,那对称是解决不了问题的,所以我们不考虑,现在设dfs(x, y)表示当前移动人是否能赢,一旦有必赢的情况就返回赢

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 500;

int n, d;
int dx[maxn], dy[maxn];
int vis[maxn][maxn];

int dfs(int x, int y) {
	if ((x-200)*(x-200) + (y-200)*(y-200) >= d*d)
		return 1;
	if (vis[x][y] != -1)
		return vis[x][y];
	for (int i = 0; i < n; i++)
		if (dfs(x+dx[i], y+dy[i]) == 0)
			return vis[x][y] = 1;
	return vis[x][y] = 0;
}

int main() {
	int x, y;
	scanf("%d%d%d%d", &x, &y, &n, &d);
	x += 200, y += 200;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &dx[i], &dy[i]);
	memset(vis, -1, sizeof(vis));
	if (dfs(x, y))
		printf("Anton\n");
	else printf("Dasha\n");
	return 0;
}

CodeForces 69D Dot (博弈+记忆化)

时间: 2024-10-15 10:10:04

CodeForces 69D Dot (博弈+记忆化)的相关文章

Codeforces 39E What Has Dirichlet Got to Do with That? 博弈+记忆化搜索

题目链接:点击打开链接 题意: 给定 a个箱子 b个球 常数n (球和箱子都是各不相同的,不会出现有一样的物品) 设 way = 把b个球放到a个箱子中的方法数, 若way >= n则游戏结束 有2个人玩游戏. 若当前轮到 X时 1. X选择增加一个箱子或增加一个球 2.若增加完后方法数>=n 则X失败 若先手必胜,则输出 Masha ,若先手必败则输出 Stas ,若为平局则输出 Missing 思路: 记忆化搜索 若当前给 a++ 或 b++都是会>=n 则当前局势必败 从其中不会&

hdu 4778 Gems Fight!(状态压缩+博弈+记忆化)

Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 1383    Accepted Submission(s): 587 Problem Description Alice and Bob are playing "Gems Fight!": There are Gems of G differe

Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)

一道概率dp问题. 题目链接:http://codeforces.com/contest/540/problem/D 题目大意:一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储i个石头,j个剪刀,k个布时,某物种的存活概率,共dp三次,算出三个物种分别的概率. 首先,我们需要把对应想求的物种概率初始化,这里以石头为例,那么对于i从1到r,不难理解dp[i][0][0]=

Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化

题意读了半年,英语太渣,题意是摆两个棋子在棋盘上作为起点,但是起点不能在#上,然后按照图的指示开始走, < 左 > 右 ^上 v下,走的时候只能按照图的指示走,如果前方是 #的话,可以走进去,但是 走进去之后便不能再走了,走的途中两个棋子不能相碰,但是最终都走到同一个#里是没事的,并且若是能走 无限步的话 输出 -1, 例如  > < 这样左右左右的走就能无限走,然后问你 两个棋子走的最大步数的和 一开始被输出-1给困住了,因为除了 .> <这样以外  还可以刚好形成一

Codeforces 509F Progress Monitoring (区间dp 或 记忆化搜索)

F. Progress Monitoring time limit per test 1 second memory limit per test 256 megabytes Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students: You are given a tree T with n vertices, specified b

Codeforces 148D Bag of mice:概率dp 记忆化搜索

题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公主先拿. 公主每次抓一只出来.龙每次在抓一只出来之后,会随机有一只老鼠跳出来(被龙吓的了...). 先抓到白老鼠的人赢.若两人最后都没有抓到白老鼠,则龙赢. 问你公主赢的概率. 题解: 表示状态: dp[i][j] = probability to win(当前公主先手,公主赢的概率) i:剩i只白

hdu4753 状态压缩dp博弈(记忆化搜索写法)

http://acm.hdu.edu.cn/showproblem.php?pid=4753 Problem Description There is a 3 by 3 grid and each vertex is assigned a number. It looks like JiuGongGe, but they are different, for we are not going to fill the cell but the edge. For instance, adding

HDU 4597 Play Game (DP,记忆化搜索,博弈)

题意:Alice和Bob玩一个游戏,有两个长度为N的正整数数字序列,每次他们两个,只能从其中一个序列,选择两端中的一个拿走.他们都希望可以拿到尽量大的数字之和, 并且他们都足够聪明,每次都选择最优策略.Alice先选择,问最终Alice拿到的数字总和是多少? 析:很明显的一个博弈题,但是用记忆化搜索来解决的,用d[la][ra][lb][rb]记录的是在a的区间只剩下la~ra,b的区间只剩下lb~rb的时候,Alice能得到的最大值, 那么我应该在让Bob取最大值中的最小才能满足这个题,当是A

uva 1559 - Nim(记忆化+博弈)

题目链接:uva 1559 - Nim 题目大意:有n个人,奇数的为一队,偶数的为一对,两队分别从一堆石子个数为S的石子堆中取石子,取到最后一个石子一方则视为失败.给出各个队员每次可取石子的上限值,然后按照顺序操作. 解题思路:dp[i][s]表示第i个选手操作时剩s个石子时为必胜还是必败.因为是取到最后一个石子的为输,所以最后递归结束的条件和不同的略有不同. 还尝试过可以将石子数减1,然后普通处理也是可以. /******************* * 取到最后一个石子的输 * *******