徐州网络赛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次操作 ...
随机推荐
- 【转】PNG图像文件格式
5.2 PNG图像文件格式 PNG是可携式网络图像(portable network graphics)的英文缩写.PNG是从网络上开始发展的,目的是替代GIF和JPG格式,PNG图像文件格式也是当 ...
- ti的硬件时钟和系统时钟同步
1.hwclock -w软到硬 hwclock -s 硬到软 2. 通过ntp网络时钟控制同步 3.etc下的localtime文件和GMT-8
- Ubuntu13.04下Eclipse中文乱码解决
参考:http://www.linuxidc.com/Linux/2011-12/50056.htm baoyu@baoyu:~$ gedit /var/lib/locales/supported.d ...
- js中数组作为参数传递的定义
下面的函数实现了一个我们想要的最基本的图片预加载效果 function preloadimages(arr){ var newimages=[] var arr=(typeof arr!= ...
- 【View】之【SimplePillarsView】可多色可圆角柱状图【demo】
当前版本:SimplePillarsView_v1.0.20140613 直接看效果图. 下附图片的设置方法:myview.setPillars(15, 0xffff00ff, 15, 5); 下附图 ...
- [转]wcout输出中文却不显示出来
准备使用UNICODE来写个控制台测试程序发现,cout无法输出UNICODE的中文字符.查找C++标准看到,其提供了wcin.wcout.wcerr.wclog用于处理wchar_t字符的输入输出. ...
- ubuntu 16.04 appstreamcli 问题
http://blog.csdn.net/zhbpd/article/details/77508675
- 编写高性能的jQuery代码
jQuery Optimization 现在jQuery已经出现在很多项目中,然而许多同学忽略了他的性能问题以及代码质量问题, 下面是我对jQuery的一些性能方面的学习. 选择器 选择器是jQuer ...
- ubuntu 使用蓝牙和minicom
Ubuntu本身一般都带了USB转串口的驱动. 1. 首先确认系统支持USBSerial,输入以下命令: lsmod | grep usbserial 2. 接上USB串口线,看看系统是否可 ...
- angular学习(十五)——Provider
转载请写明来源地址:http://blog.csdn.net/lastsweetop/article/details/60966263 Provider简单介绍 每一个web应用都是由多个对象协作完毕 ...