Stake Your Claim
//
#include <iostream>
#include <cstring>
#include <cstdio>
#define INF 1000000
for (int i = 0; i < 4; ++i) {
int x, y;
x = m + xx[i];
y = n + yy[i];
if (x >= 0 && x < N && y >= 0 && y < N && !vis[x][y] && Map[x][y] == num) {
*s = *s + 1;
vis[x][y] = 1;
DFS(num, x, y, s);
}
}
}
int alpha_beta(int cnt, int player, int alpha, int beta, int now_cnt, int now_player) {
int i, j, val;
if (cnt == N * N) {
score0 = score1 = 0;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
if (Map[i][j] == 1 && !vis[i][j]) {
vis[i][j] = 1;
int score = 1;
DFS(1, i, j, &score);
if (score > score0)
score0 = score;
}
if (Map[i][j] == 2 && !vis[i][j]) {
vis[i][j] = 1;
int score = 1;
DFS(2, i, j, &score);
if (score > score1)
score1 = score;
}
}
return score0 - score1;
}
for (i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
if (Map[i][j])
continue;
Map[i][j] = 1;
val = alpha_beta(cnt + 1, 1 - player, alpha, beta, now_cnt, now_player);
Map[i][j] = 0;
if (val > alpha) {
alpha = val;
if (now_player == 0 && cnt == now_cnt) {
X = i;
Y = j;
}
}
if (alpha >= beta)
return alpha;
}
return alpha;
}
else {
for (i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
if (Map[i][j])
continue;
Map[i][j] = 2;
val = alpha_beta(cnt + 1, 1 - player, alpha, beta, now_cnt, now_player);
Map[i][j] = 0;
if (val < beta) {
beta = val;
if (now_player == 1 && cnt == now_cnt) {
X = i;
Y = j;
}
}
if (alpha >= beta)
return beta;
}
return beta;
}
}
{
int S0, S1, cnt;
char ch;
while (cin >> N) {
if (N == 0)
break;
S0 = S1 = cnt = 0;
memset(Map, 0, sizeof(Map));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> ch;
if (ch == '0') {
cnt++;
S0++;
Map[i][j] = 1;
}
else if (ch == '1') {
cnt++;
S1++;
Map[i][j] = 2;
}
else
Map[i][j] = 0;
}
}
int score0 = alpha_beta(cnt, 0, -INF, INF, cnt, 0);
printf("(%d,%d) %d\n", X, Y, score0);
}
else {
int score1 = alpha_beta(cnt, 1, -INF, INF, cnt, 1);
printf("(%d,%d) %d\n", X, Y, -score1);
}
}
return 0;
}
Stake Your Claim相关推荐
- ACM题集以及各种总结大全(转)
ACM题集以及各种总结大全! 虽然退役了,但是整理一下,供小弟小妹们以后切题方便一些,但由于近来考试太多,顾退役总结延迟一段时间再写!先写一下各种分类和题集,欢迎各位大牛路过指正. 一.ACM入门 关 ...
- 前前前世用计算机,前前前世
At last "Hello!" You've opened your eyes But why won't you even look me in the eyes? What' ...
- csdn无人驾驶汽车_无人驾驶汽车100年历史
csdn无人驾驶汽车 The first self-driving vehicles were ships. After centuries of wrestling with wind and wa ...
- 计算机英语名词简释(转)
计算机英语名词简释 一.著名公司及其商标名 Microsoft: 有时缩略为MS,是全球最著名的软件商,美国软件巨头微软公司的名字.Microsoft其实是由两个英语单词组成:Micro意为" ...
- 计算机英语名词简释(轉載)
计算机英语名词简释 一.著名公司及其商标名 Microsoft: 有时缩略为MS,是全球最著名的软件商,美国软件巨头微软公司的名字.Microsoft其实是由两个英语单词组成:Micro意为" ...
- 计算机英语名词简释(转载)
计算机英语名词简释 一.著名公司及其商标名 Microsoft: 有时缩略为MS,是全球最著名的软件商,美国软件巨头微软公司的名字.Microsoft其实是由两个英语单词组成:Micro意为" ...
- 极大极小算法和AlphaBeta剪枝算法
作为菜鸟,先贴上参考博文: 1.极小极大算法 2.<<CS 161 Recitation Notes - The Minimax Algorithm>> 3.<PC游戏编 ...
- 使用 go 实现 Proof of Stake 共识机制
使用 go 实现 Proof of Stake 共识机制 什么是 Proof of Stake 在PoW中,节点之间通过hash的计算力来竞赛以获取下一个区块的记账权,而在PoS中,块是已经铸造好的, ...
- 【译】The missing explanation of Proof of Stake Version 3
在每一个加密货币中,都必须有一些共识机制来保持整个分布式网络的同步. 当比特币首次推出时,它推出了工作证明(PoW)系统. PoW是通过反复加密散列一块数据(块头)来完成的. 由于单向哈希如何工作. ...
最新文章
- puppet yum模块、配置仓储、mount模块
- Windows上打开大文件的工具
- java课程设计题目及代码中国象棋,写的太详细了
- Mac-连接Windows远程桌面软件
- shape file与coverage叠加的问题
- JavaScript事件捕获与事件冒泡原理 IE和DOM之间存在哪些主要差别
- bilibili【考研英语词汇】
- web前端课程设计——K.X的博客
- 清理电脑垃圾的七个BAT文件
- 阿里云移动推送学习笔记
- Python文本处理,依次读取文本每一行,查找每一行特定位置的元素,生成列表,去重
- vue+antDesign实现树形数据展示并表格父子级选中和取消联动
- iOS苹果账号/证书/推送证书之我见
- CL210管理存储--对象存储
- 微信小程序day01
- 服务器站群16c多少个ip?不同C段IP怎么计算
- 魅族l681q详细开启Usb调试模式的步骤
- 运行TensorFlow出现The TensorFlow library wasn‘t compiled to use FMA instructions)代码
- Spring整合Mybatis之DAO层、Service层开发
- 我的世界mod整合包java_我的世界1.7.10食物、匠魂与超能力向整合包(附JAVA)
热门文章
- 如何设计一个超级牛牛牛逼的 Feed 流系统
- Python进阶之路 3.4.1 布尔值和布尔变量
- Tomcat监控工具之probe(四步完成安装配置,中英文界面切换)
- python编写程序模拟猫狗大战
- 终于有人把“计算机底层原理“全部总结出来了
- GUI原理 - 色彩王国
- VS Code Remote Development插件的需求分析和逆向工程
- 如何给Ubuntu16.04更新软件
- android横向自动滚动列表,android横向循环自动滚动
- 精诚CRM系统如何预防客户流失,提升客户留存