HDU 5754 博弈(威佐夫博弈)
2016-07-26 20:22
246 查看
这个题除了皇后的可以套用一下威佐夫博弈以外其他的都可以找规律找出来,主要为了学习一下威佐夫博弈,
威佐夫博弈:给两堆石子,每次都可以从其中一堆石子中取n个石子或者从两堆石子中都取n个石子,最后将石子取完的获胜。
解是根据:
来判断谁获胜的,但是这个题可能是因为精度问题,用这个直接判断AC不了。=.=
也可以根据规律来打个威佐夫博弈的表
AC代码:
威佐夫博弈:给两堆石子,每次都可以从其中一堆石子中取n个石子或者从两堆石子中都取n个石子,最后将石子取完的获胜。
解是根据:
int k = abs(n - m); n = (int)((double)k * (1.0 + sqrt(5.0)) / 2.0); if (n == m) printf("G\n"); else printf("B\n");
来判断谁获胜的,但是这个题可能是因为精度问题,用这个直接判断AC不了。=.=
也可以根据规律来打个威佐夫博弈的表
int x = 1, y = 1; for(int i = 1; ; ++i) { int add = 1; while(vis[x + add] || vis[y + 1 + add]) add++; x += add, y += add + 1; if(x >= maxn || y >= maxn) break; vis[x] = vis[y] = true; matc[x][y] = true; matc[y][x] = true; }
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
using namespace std;
const int eps = 1e-6;
const int maxn = 1200 + 50;
int s[maxn][maxn];
int T;
int n,m;
int knight(int x,int y) {
if(x == y && (x - 1) % 3 == 0) return 0;
else if((x + 1 == y + 2) && (x % 3 == 0)) return 1;
else if((y + 1 == x + 2) && (y % 3 == 0)) return 1;
return -1;
}
bool matc[maxn][maxn];
bool vis[maxn];
int main() {
int x = 1, y = 1; for(int i = 1; ; ++i) { int add = 1; while(vis[x + add] || vis[y + 1 + add]) add++; x += add, y += add + 1; if(x >= maxn || y >= maxn) break; vis[x] = vis[y] = true; matc[x][y] = true; matc[y][x] = true; }
scanf("%d",&T);
while(T--) {
int t;
scanf("%d%d%d",&t,&n,&m);
if (t == 4) {
if (matc
[m]) printf("G\n");
else printf("B\n");
// int k = abs(n - m);
// n = (int)((double)k * (1.0 + sqrt(5.0)) / 2.0);
// if (n == m) printf("G\n");
// else printf("B\n");
} else if (t == 2) {
if (n == m) printf("G\n");
else printf("B\n");
} else if (t == 1) {
if ((n & 1) && (m & 1)) printf("G\n");
else printf("B\n");
} else {
int t = knight(n, m);
if (t == -1) printf("D\n");
else if (t == 1) printf("B\n");
else printf("G\n");
}
}
return 0;
}
相关文章推荐
- 新思路现动网新漏洞
- ASP木马后门新思路
- mysql 分页优化解析
- Android生存指南之:解Bug策略与思路问题的详解
- jQuery.clean使用方法及思路分析
- [转]学习新东西的唯一方法
- iphone5适配 有如下集中种思路
- 组建无线网络的六条思路
- Windows2003服务器安全配置的一些思路
- Oracle数据库文件恢复与备份思路
- 网络故障一览
- 思路决定出路
- MySQL调优
- 清晰透彻而又详略得当的答案里,包含着作者独特的理解和思路
- 资讯类网站的运营思路
- 数据传输
- # C 语言编写二进制/十六进制编辑器
- 网络建站流程思路
- 数字数码管-解题思路及过程
- 加密与解密_Playfair密码变种加密方法-解题思路及过程