【CCF】棋局评估
博弈论极小极大搜索,记忆化+状压
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=2e4+;
const int inf=;
int a[];
int three[];
int tmp[];
int ans[maxn][];
void pre(){
three[]=;
for(int i=;i<;i++){
three[i]=three[i-]*;
}
}
int judge(vector<int> tmp){
int res=;
for(int i=;i<;i++){
res+=(tmp[i]==);
}
//ALice
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
//Bob
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
//Tie
if(res==) return ;
//None
return inf; } int dfs(int s,int p){
if(ans[s][p]!=inf) return ans[s][p];
vector<int> tmp;
for(int i=;i<;i++) tmp.push_back();
int ss=s;
int cnt=;
while(ss){
tmp[cnt]=ss%;
ss/=;
cnt++;
}
int x=judge(tmp);
if(x!=inf) return ans[s][p]=x;
if(p==){
int res=-inf;
for(int i=;i<;i++){
if(tmp[i]==){
res=max(res,dfs(s+*three[i],));
}
}
return ans[s][p]=res;
}else{
int res=inf;
for(int i=;i<;i++){
if(tmp[i]==){
res=min(res,dfs(s+*three[i],));
}
}
return ans[s][p]=res;
}
}
int main(){
int T;
scanf("%d",&T);
pre();
while(T--){
for(int i=;i<maxn;i++){
ans[i][]=ans[i][]=inf;
}
for(int i=;i<;i++) scanf("%d",&a[i]);
int s=;
for(int i=;i<;i++){
s+=a[i]*three[i];
}
int ans=dfs(s,);
printf("%d\n",ans);
}
return ;
}
【CCF】棋局评估的更多相关文章
- ccf 201803-4 棋局评估(Python实现)
一.原题 问题描述 试题编号: 201803-4 试题名称: 棋局评估 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很 ...
- ccf 201803-4 棋局评估 (对抗搜索)
棋局评估 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很简单:两人轮流往3*3的棋盘中放棋子,Alice放的是“X”,Bob放的是“O”,Alice执先.当同一种棋子占据一行.一列 ...
- CCF(棋局评估)博弈论+对抗搜索+DFS
201803-4 棋局评估 这题主要使用对抗搜索,也就是每一步寻找可以下棋的位置,通过在这一步下棋看最后会取的什么样的分数. #include<iostream> #include< ...
- CCF-CSP题解 201803-4 棋局评估
求当前井字棋局的得分. 用dfs虚构一下搜索树,每个节点对应一个不同的棋局. 每个节点有一个situation()情况评估,若胜负已定,则对应该棋局的评分:否则为0,表示胜负未定或平局. 每个节点还有 ...
- CSP201803-4棋局评估
问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很简单:两人轮流往3*3的棋盘中放棋子,Alice放的是“X”,Bob放的是“O”,Alice执先.当同一种棋子占据一行.一列或一条对角 ...
- 为何谷歌围棋AI AlphaGo可能会把李世石击溃
/* 版权声明:可以随意转载,转载时请标明文章原始出处和作者信息 .*/ author: 张俊林 谷歌DeepMind开发的人工智能围棋程序AlphaGo以5:0的压倒性优势击败了欧洲围棋冠军.专业二 ...
- AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search
转载请声明 http://blog.csdn.net/u013390476/article/details/50925347 前言: 围棋的英文是 the game of Go,标题翻译为:<用 ...
- 机器学习系列(8)_读《Nature》论文,看AlphaGo养成
作者:viewmode=contents">龙心尘 && viewmode=contents">寒小阳 时间:2016年3月. 出处:http://bl ...
- python 2048游戏控制器
2048游戏控制器 1 evaluate 要用程序来处理就得对现实的问题进行量化,用数字来表示.在2048游戏中,我们的输入是一个棋局,让我们输出一个移动方向,这样我们需要对棋局进行量化,即我们要评估 ...
随机推荐
- Redis性能优化之redis.cnf配置参数
redis调优总结 1.相应的参数调优 加内存2.redis使用结构调优3.使用合理的数据类型说明:redis存储的数据为redis hash(字符映射表) 单key多字段结构. 1)调整配置文件中配 ...
- 用vscode开发vue应用[转]
https://segmentfault.com/a/1190000019055976 现在用VSCode开发Vue.js应用几乎已经是前端的标配了,但很多时候我们看到的代码混乱不堪,作为一个前端工程 ...
- firstElectron_web5 安装
小娜 搜 cmd 右键 管理员运行 1.装全局 这样 不用每次都下载 因为包挺大的 还有用cnpm 要不太慢 cnpm install electron --save-dev --save-exact ...
- HTML之网页的基本介绍
一.web的基本介绍 web就是world wide web的缩写,称之为全球广域网,俗称WWW 可以将web理解成一种当前的互联网,对于我们来说更多的就是网站服务 网站我们可以理解成是由很多网页组合 ...
- 在 webpack 中使用 ECharts
http://echarts.baidu.com/tutorial.html#%E5%9C%A8%20webpack%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20ECharts W ...
- pandas小结
pandas part I: # 总结: DataFrame.loc[0:5] 一共6行数据,而切片[0:5]只有5个数据 在对df的行数据删除后,有些index已缺失,此时用 iloc[]来按照位置 ...
- ArcMap所有Command GUID
The information in this topic is useful if you're trying to programmatically find a built-in command ...
- 身份证号正则校验(js校验+JAVA校验)
js校验身份证号[15位和18位] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
- 利用React遍历数组,并且用数组的元素生成<li>arrItem</li>标签组
var numbers = [1,2,3,4,5,6,7,8,9]; ReactDom.render({ <ul> { numbers.map(function(item){ return ...
- Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...