博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM 2017 南宁区域赛 Rake it in(对抗搜索)
阅读量:2135 次
发布时间:2019-04-30

本文共 1322 字,大约阅读时间需要 4 分钟。

题目大意:

    Alice和Bob在玩一种名为“Rake It In”的游戏,起初有一个4*4的棋盘,每一格为一个1~10的整数,两人轮流行动,各自k次,行动者选择棋盘中某一个2*2的区域,将这四个元素求和,加到最终答案中,并将四个元素按逆时针旋转90度,Alice先行。Alice的目标是最大化最后的答案,Bob相反。请写一个程序计算,在两人都最聪明的情况下,最终答案为多少。

题解:

     对抗搜索

#include
#include
#include
#include
#include
#include
#include
using namespace std;const int INF=1000000007;typedef long long ll;int k;int a[10][10];int calc(int i,int j){ return a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];}void trans(int x,int y){ int t=a[x][y]; a[x][y]=a[x][y+1]; a[x][y+1]=a[x+1][y+1]; a[x+1][y+1]=a[x+1][y]; a[x+1][y]=t;}void ftrans(int x,int y){ int t=a[x][y]; a[x][y]=a[x+1][y]; a[x+1][y]=a[x+1][y+1]; a[x+1][y+1]=a[x][y+1]; a[x][y+1]=t;}int play(int t){ if(t==2*k) { int score(INF); for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) score=min(score,calc(i,j)); return score; } else if(t&1) { int score(0); for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) { trans(i,j); score=max(score,play(t+1)+calc(i,j)); ftrans(i,j); } return score; } else { int score(INF); for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) { trans(i,j); score=min(score,play(t+1)+calc(i,j)); ftrans(i,j); } return score; } //当前算的我必须要用到后面的结果}int main(){ //freopen("input.txt","r",stdin); int T; cin>>T; while(T--) { cin>>k; for(int i=1;i<=4;i++) for(int j=1;j<=4;j++) cin>>a[i][j]; cout<
<

 

转载地址:http://vufgf.baihongyu.com/

你可能感兴趣的文章
简述极大似然估计
查看>>
用线性判别分析 LDA 降维
查看>>
用 Doc2Vec 得到文档/段落/句子的向量表达
查看>>
使聊天机器人具有个性
查看>>
使聊天机器人的对话更有营养
查看>>
一个 tflearn 情感分析小例子
查看>>
attention 机制入门
查看>>
手把手用 IntelliJ IDEA 和 SBT 创建 scala 项目
查看>>
双向 LSTM
查看>>
GAN 的 keras 实现
查看>>
AI 在 marketing 上的应用
查看>>
Logistic regression 为什么用 sigmoid ?
查看>>
Logistic Regression 为什么用极大似然函数
查看>>
SVM 的核函数选择和调参
查看>>
LightGBM 如何调参
查看>>
用 TensorFlow.js 在浏览器中训练神经网络
查看>>
cs230 深度学习 Lecture 2 编程作业: Logistic Regression with a Neural Network mindset
查看>>
梯度消失问题与如何选择激活函数
查看>>
为什么需要 Mini-batch 梯度下降,及 TensorFlow 应用举例
查看>>
为什么在优化算法中使用指数加权平均
查看>>