【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游戏中,我们的输入是一个棋局,让我们输出一个移动方向,这样我们需要对棋局进行量化,即我们要评估 ...
随机推荐
- show processlist使用介绍
这个命令中最关键的就是state列,mysql列出的状态主要有以下几种: Checking table 正在检查数据表(这是自动的).Closing tables 正在将表中修改的数据刷新到磁盘中,同 ...
- 洛谷 P2264 情书
题目背景 一封好的情书需要撰写人全身心的投入.lin_toto同学看上了可爱的卡速米想对她表白,但却不知道自己写的情书是否能感动她,现在他带着情书请你来帮助他. 题目描述 为了帮助lin_toto,我 ...
- 使用Cordova将您的前端JavaScript应用打包成手机原生应用
假设我用JavaScript和HTML开发了一个前端应用,我想把该应用打包成能直接在手机上安装和运行(不通过浏览器)的原生应用,例如像下面这样.对应用的用户来说,他们得到的用户体验和真正的用Andro ...
- (转)SpringMVC学习(五)——SpringMVC的参数绑定
http://blog.csdn.net/yerenyuan_pku/article/details/72511611 SpringMVC中的参数绑定还是蛮重要的,所以单独开一篇文章来讲解.本文所有案 ...
- UVA - 1252 Twenty Questions (状压dp)
状压dp,用s表示已经询问过的特征,a表示W具有的特征. 当满足条件的物体只有一个的时候就不用再猜测了.对于满足条件的物体个数可以预处理出来 转移的时候应该枚举询问的k,因为实际上要猜的物品是不确定的 ...
- Resize a UIImage the right way
When deadlines loom, even skilled and experienced programmers can get a little sloppy. The pressure ...
- 8 Java 归并排序(MergerSort)
图片素材与文字描述来自:尚硅谷-韩顺平数据结构与算法. 1.基本思想 归并排序是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divi ...
- Kernel Stack Overflow(转)
0x00 漏洞代码 stack_smashing.c #include <linux/init.h> #include <linux/module.h> #include &l ...
- APIO2019&&THUSC2019游记
APIO2019懵十三记: day0: 早上和ljx从沈阳出发,下午一点到的首师大附. 由于工作人员中午十二点就散了,我们就先去试机了. 下午三点接到狗牌和T恤,晚上买麦当劳回如意吃. 晚上还有场模拟 ...
- 无法连接Elasticsearch解决方案
前言 最近还是在弄ELK,并且在测试Logstash从kafka消费日志(最后输出到Elasticsearch). 测试完毕后,在kibana中,并没有发现Elasticsearch中的数据. 后来装 ...