徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly face the choice, each time you choose the game will provide 1-31−3 options, the player can only choose one of them. Each option has an effect on a "score" parameter in the game. Some options will increase the score, some options will reduce the score, and some options will change the score to a value multiplied by -1−1 .
That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -1−1. The score before the selection is 88. Then selecting option 11 will make the score become 99, and selecting option 22 will make the score 77 and select option 33 to make the score -8−8. Note that the score has an upper limit of 100100 and a lower limit of -100−100. If the score is 9999 at this time, an option that makes the score +2+2 is selected. After that, the score will change to 100100 and vice versa .
After all the choices have been made, the score will affect the ending of the game. If the score is greater than or equal to a certain value kk, it will enter a good ending; if it is less than or equal to a certain value ll, it will enter the bad ending; if both conditions are not satisfied, it will enter the normal ending. Now, Koutarou and Sena want to play the good endings and the bad endings respectively. They refused to give up each other and finally decided to use the "one person to make a choice" way to play the game, Koutarou first choose. Now assume that they all know the initial score, the impact of each option, and the kk, ll values, and decide to choose in the way that works best for them. (That is, they will try their best to play the ending they want. If it's impossible, they would rather normal ending than the ending their rival wants.)
Koutarou and Sena are playing very happy, but I believe you have seen through the final ending. Now give you the initial score, the kk value, the ll value, and the effect of each option on the score. Can you answer the final ending of the game?
Input
The first line contains four integers n,m,k,ln,m,k,l(1\le n \le 10001≤n≤1000, -100 \le m \le 100−100≤m≤100 , -100 \le l < k \le 100−100≤l<k≤100), represents the number of choices, the initial score, the minimum score required to enter a good ending, and the highest score required to enter a bad ending, respectively.
Each of the next nn lines contains three integers a,b,ca,b,c(a\ge 0a≥0 , b\ge0b≥0 ,c=0c=0 or c=1c=1),indicates the options that appear in this selection,in which a=0a=0 means there is no option to increase the score in this selection, a>0a>0 means there is an option in this selection to increase the score by aa ; b=0b=0 means there is no option to decrease the score in this selection, b>0b>0 means there is an option in this selection to decrease the score by bb; c=0c=0 means there is no option to multiply the score by -1−1 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -1−1. It is guaranteed that a,b,ca,b,c are not equal to 00 at the same time.
Output
One line contains the final ending of the game. If it will enter a good ending,print "Good Ending"(without quotes); if it will enter a bad ending,print "Bad Ending"(without quotes);otherwise print "Normal Ending"(without quotes).
样例输入1复制
3 -8 5 -5
3 1 1
2 0 1
0 2 1
样例输出1复制
Good Ending
样例输入2复制
3 0 10 3
0 0 1
0 10 1
0 2 1
样例输出2复制
Bad Ending
题目来源
题意:
两个人玩游戏 初始分值是m 进行n次操作
每次操作有三种选项 a,b,c
a不为0表示 可以选择加a;b不为0表示 可以选择减b; c不为0表示 可以选择乘-1
分值的上下界是-100和100
一个人希望分值最后大于k 一个人希望分值最后小于l 求最后分值会落在哪个范围
思路:
其实不太会记忆化搜索 本来以为就是dp 但是写了半天写不出来
其实记忆化搜索就是 dfs递归 + dp记录
dfs过程中一旦发现dp数组已经有值了就直接返回 这样对dfs进行了剪枝
用dp[id][x]表示在分值为x时进行第id次操作的结果 1表示先手必胜 0表示平手 -1表示先手必败
根据递归返回的结果 加上当前的局数来判断当前结果
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>
#include <map> #define inf 0x3f3f3f3f
using namespace std; typedef long long LL; int n, m, l, k;
const int maxn = ;
int dp[maxn][];
struct node{
int a, b, c;
}op[maxn]; int solve(int id, int x)
{
int win, lose, done, tmp;
if(dp[id][x] <= ){
return dp[id][x];
}
if(id == n + ){
if(x >= k) return ;
if(x <= l) return -;
return ;
} win = lose = done = ;
if(id % ){
if(op[id].a != ){
tmp = solve(id + , min(x + op[id].a, ));
if(tmp == ){
win = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
lose = ;
}
}
if(op[id].b != ){
tmp = solve(id + , max(, x - op[id].b));
if(tmp == ){
win = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
lose = ;
}
}
if(op[id].c != ){
tmp = solve(id + , - x);
if(tmp == ){
win = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
lose = ;
}
}
if(win == ){
return dp[id][x] = ;
}
else if(done == ){
return dp[id][x] = ;
}
else{
return dp[id][x] = -;
}
}
else{
if(op[id].a != ){
tmp = solve(id + , min(x + op[id].a, ));
if(tmp == ){
lose = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
win = ;
}
}
if(op[id].b != ){
tmp = solve(id + , max(, x - op[id].b));
if(tmp == ){
lose = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
win = ;
}
}
if(op[id].c != ){
tmp = solve(id + , - x);
if(tmp == ){
lose = ;
}
if(tmp == ){
done = ;
}
if(tmp == -){
win = ;
}
}
if(win == ){
return dp[id][x] = -;
}
else if(done == ){
return dp[id][x] = ;
}
else{
return dp[id][x] = ;
}
} } int main()
{
while(scanf("%d%d%d%d", &n, &m, &k, &l) != EOF){
m += ;
l += ;
k += ;
for(int i = ; i <= n; i++){
scanf("%d%d%d", &op[i].a, &op[i].b, &op[i].c);
} //memset(dp, 62, sizeof(dp));
//cout<<dp[0]<<endl;
memset(dp, inf, sizeof(dp));
int ans = solve(, m);
if(ans == ){
printf("Good Ending\n");
}
else if(ans == -){
printf("Bad Ending\n");
}
else{
printf("Normal Ending\n");
}
}
return ;
}
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly face the choice, each time you choose the game will provide 1-31−3 options, the player can only choose one of them. Each option has an effect on a "score" parameter in the game. Some options will increase the score, some options will reduce the score, and some options will change the score to a value multiplied by -1−1 .
That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -1−1. The score before the selection is 88. Then selecting option 11 will make the score become 99, and selecting option 22 will make the score 77 and select option 33 to make the score -8−8. Note that the score has an upper limit of 100100 and a lower limit of -100−100. If the score is 9999 at this time, an option that makes the score +2+2 is selected. After that, the score will change to 100100 and vice versa .
After all the choices have been made, the score will affect the ending of the game. If the score is greater than or equal to a certain value kk, it will enter a good ending; if it is less than or equal to a certain value ll, it will enter the bad ending; if both conditions are not satisfied, it will enter the normal ending. Now, Koutarou and Sena want to play the good endings and the bad endings respectively. They refused to give up each other and finally decided to use the "one person to make a choice" way to play the game, Koutarou first choose. Now assume that they all know the initial score, the impact of each option, and the kk, ll values, and decide to choose in the way that works best for them. (That is, they will try their best to play the ending they want. If it's impossible, they would rather normal ending than the ending their rival wants.)
Koutarou and Sena are playing very happy, but I believe you have seen through the final ending. Now give you the initial score, the kk value, the ll value, and the effect of each option on the score. Can you answer the final ending of the game?
Input
The first line contains four integers n,m,k,ln,m,k,l(1\le n \le 10001≤n≤1000, -100 \le m \le 100−100≤m≤100 , -100 \le l < k \le 100−100≤l<k≤100), represents the number of choices, the initial score, the minimum score required to enter a good ending, and the highest score required to enter a bad ending, respectively.
Each of the next nn lines contains three integers a,b,ca,b,c(a\ge 0a≥0 , b\ge0b≥0 ,c=0c=0 or c=1c=1),indicates the options that appear in this selection,in which a=0a=0 means there is no option to increase the score in this selection, a>0a>0 means there is an option in this selection to increase the score by aa ; b=0b=0 means there is no option to decrease the score in this selection, b>0b>0 means there is an option in this selection to decrease the score by bb; c=0c=0 means there is no option to multiply the score by -1−1 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -1−1. It is guaranteed that a,b,ca,b,c are not equal to 00 at the same time.
Output
One line contains the final ending of the game. If it will enter a good ending,print "Good Ending"(without quotes); if it will enter a bad ending,print "Bad Ending"(without quotes);otherwise print "Normal Ending"(without quotes).
样例输入1复制
3 -8 5 -5
3 1 1
2 0 1
0 2 1
样例输出1复制
Good Ending
样例输入2复制
3 0 10 3
0 0 1
0 10 1
0 2 1
样例输出2复制
Bad Ending
题目来源
徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(记忆化搜索)
https://nanti.jisuanke.com/t/31454 题意 两个人玩游戏,最初数字为m,有n轮,每轮三个操作给出a b c,a>0表示可以让当前数字加上a,b>0表示可以让 ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)
query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...
- ICPC 2019 徐州网络赛
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...
- [徐州网络赛]Longest subsequence
[徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...
- ACM-ICPC2018徐州网络赛 BE, GE or NE(对抗搜索+博弈+记忆化)
BE, GE or NE 23.58% 1000ms 262144K In a world where ordinary people cannot reach, a boy named &quo ...
- 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次操作 ...
随机推荐
- BCM_GPIO驱动测试
在写内核驱动的时候,最好先在uboot上,进行裸板测试,验证寄存器,再移植到内核中,这样可以熟悉寄存器,也排除内核中的一些干扰. /********************************** ...
- 基本上每个应用程序领域的程序员都有使用 C++
C++ 的使用基本上每个应用程序领域的程序员都有使用 C++. C++ 通常用于编写设备驱动程序和其他要求实时性的直接操作硬件的软件. C++ 广泛用于教学和研究. 任何一个使用苹果电脑或 Windo ...
- 其它系统与domino系统单点登录的实现方式
其它系统与domino系统单点登录的实现方式 [背景] 随着企业中业务不断增多,用户处理不同的业务则须要频繁的切换不同的系统进行操作.而用户则须要记住各个系统的username.password ...
- 阮一峰---javascript系列
2013.05.11:如何做到 jQuery-free?(29条评论) 2013.01.23:JavaScript Source Map 详解(14条评论) 2013.01.14:Javascript ...
- 【View】之【SimpleWaveView】可多色可刷新的加速球、进度球【demo】
当前版本:SimpleWaveView_v1.0.20140618 先看效果图,这个加速球是动态的,并且当调用了myView.setRefresh(0.8F);方法后可以从当前值动态降到0再升到80% ...
- mysql中,now()函数和sysdate()函数有什么区别?
问题描述: 今天在看mysql的时间函数,now()和sysdate(),记录下两者之间有什么不同. 实验过程: 1.执行以下的两个语句: mysql),now(); +--------------- ...
- ubuntu压缩
.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)-------------------------- ...
- laravel 模版赋值
1)一般赋值是直接用view助手函数返回的 return view('Index/index', ['key'=>'value']); 2)一般做系统时,我们都会有一个共同控制器,其他控制器继承 ...
- php开n次方
php有开平方函数 sqrt,但没开n次方的函数 网上用根据什么数字原理,可用次方(pow)弄开方,格式为:pow(number, 1/ 开方数) 例如: 4的开平方,可以写成 pow(4, 1/2) ...
- linux--解决oracle sqlplus 中上下左右backspace不能用
1. 解决不能backspace 方法1: stty erase ^h 在oracle用户下:在用户环境配置文件.bash_profile中加入如下语句 stty erase ^h 方法2:在sec ...