ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(记忆化搜索)
https://nanti.jisuanke.com/t/31454
题意
两个人玩游戏,最初数字为m,有n轮,每轮三个操作给出a b c,a>0表示可以让当前数字加上a,b>0表示可以让当前数字减去b,c=1表示可以让当前数字乘-1,数字范围为[-100, 100],如果加/减出范围则直接等于边界,最终结果数字x>=R则为Good Ending,x<=L则为Bad Ending,否则Normal Ending,第一个人希望好结局,第二个人希望坏结局,如果没有办法就希望平局,每个人都做最优选择。求最终结果
分析
一开始题目没看懂啊。。很蒙,然后学弟就秒了。
所以状态1000*200,考虑暴力求解。又是博弈题,那当然是记忆化搜索啦。把每个状态都搜一下,优先选赢,其次才是平局,最后才是输。
因为分数可能为负数,所以这里加了个115变成正数来计算,方便得多。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mod 1000000007
int n, L, R, dp[][];
typedef struct Res{
int x, y, z;
}Res;
Res s[];
int Go(int x, int y, int t=){
if(x==) y = min(y+t, );
else if(x==) y = max(y-t, );
else y += *(-y);
return y;
}
int dfs(int id, int x){
int win, lose, done, temp;
if(dp[id][x]<=)
return dp[id][x];
if(id==n+){
if(x>=R) return ;
if(x<=L) return -;
return ;
}
win = lose = done = ;
if(id%){//先手,想造出GoodEnding
if(s[id].x!=){
temp = dfs(id+, Go(, x, s[id].x));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(s[id].y!=){
temp = dfs(id+, Go(, x, s[id].y));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(s[id].z!=){
temp = dfs(id+, Go(, x));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(win) return dp[id][x] = ;
else if(done) return dp[id][x] = ;
else return dp[id][x] = -;
}else{
if(s[id].x!=){
temp = dfs(id+, Go(, x, s[id].x));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(s[id].y!=){
temp = dfs(id+, Go(, x, s[id].y));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(s[id].z!=){
temp = dfs(id+, Go(, x));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(win) return dp[id][x] = -;
else if(done) return dp[id][x] = ;
else return dp[id][x] = ;
}
}
int main(){
int ans, m, i;
scanf("%d%d%d%d", &n, &m, &R, &L);
R += , L += ;
for(i=;i<=n;i++)
scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].z);
memset(dp, , sizeof(dp));
ans = dfs(, m+);
if(ans==) puts("Good Ending");
else if(ans==-) puts("Bad Ending");
else puts("Normal Ending");
return ;
}
ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(记忆化搜索)的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...
- ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(博弈,记忆化搜索)
链接https://nanti.jisuanke.com/t/31454 思路 开始没读懂题,也没注意看数据范围(1000*200的状态,记忆化搜索随便搞) 用记忆化搜索处理出来每个状态的胜负情况 因 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE 【模拟+博弈】
题目:戳这里 题意:A和B博弈,三种操作分别是x:加a,y:减b,z:取相反数.当x或y或z为0,说明该操作不可取,数据保证至少有一个操作可取,给定一个区间(l,k)和原始数字m,如果A和B在n次操作 ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
随机推荐
- linq 左连接后实现与主表一对一关系数据
var query1 = from r in _residentRepository.GetAll() join i in _inLogRepository.GetAll() on r.Id equa ...
- 用Angular部署Cesium
用到的集成开发环境是WebStrom,Cesium版本是1.50.0,Angular版本是6.2.4 1.首先我们安装cesium,在webstorm中的Termianl中输入 npm instal ...
- 码农人生——从未学过Android如何开发Android App 案例讲解-第002期案例
标题有点晃眼,本次分享是002期博文的实践故事,不会有任何代码.也不会教别人android 如何开发,类似博文已经有大批大批,而且还会有陆陆续续的人写,我写的文章,主要是经验之谈,希望总结出的一些方法 ...
- IDF-cookie欺骗
原题链接:http://ctf.idf.cn/game/web/40/index.php 进入题目,发现一个长字符串,放到md5.base64均无意义. 观察地址栏,发现有两个参数,line和file ...
- 读写锁ReentrantReadWriteLock的使用
package com.thread.test.Lock; import java.util.Random; import java.util.concurrent.locks.Lock; impor ...
- C# for循环或者foreach往List中添加对象的时候前面的数据总被最后加入的覆盖
昨天我旁边小姐姐遇到一个问题,就是在执行for循环往list添加数据的时候,前面的数据信息总是被后面的数据信息所覆盖. 这样编写就会造成这样的数据效果:(所有的数据都会被覆盖) 问题原因:对 ...
- rtsp 流媒体服务器,播放器
https://github.com/EasyDSS/EasyPlayer-RTSP-Android EasyPlayer EasyPlayer RTSP Android 播放器是由紫鲸团队开发和维护 ...
- python3 闭包函数
'''闭包函数:内部函数引用外部函数变量(非全局变量)'''def func(y): x = 1 def func1(): print(x, y) return func1 f = func(2)pr ...
- 压力测试Apache
在做类似商城秒杀系统的同事都知道要在支持高并发,高可用的环境下进行多次的压力测试来防止自己的项目结构被高额的点击量击穿,导致商品超卖等损失 介绍一款简单的软件 xampp xam里带了Apache服务 ...
- matlab读取csv文件数据并绘图
circle.m(画二维圆的函数) %该函数是画二维圆圈,输入圆心坐标和半径%rectangle()函数参数‘linewidth’修饰曲线的宽度%'edgecolor','r',edgecolor表示 ...