2018ACM-ICPC徐州赛区网络赛: B. BE, GE or NE(博弈+记忆化搜索)

 

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).

 

题意:

两个人玩游戏,最初数字为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,第一个人希望好结局,第二个人希望坏结局,如果没有办法就希望平局,每个人都做最优选择求最终结果

 

思路:

这种题记忆化搜索没跑了,dp[x][y]表示:如果x轮后分数为y,那么当前玩家是否可以必胜(1)/必败(-1)/追平(0)

具体看代码(虽然很长但是很好看懂吧)

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define mod 1000000007
int n, L, R, dp[1005][250];
typedef struct Res
{
	int x, y, z;
}Res;
Res s[1005];
int Go(int x, int y, int t=0)
{
	if(x==1)  y = min(y+t, 215);
	else if(x==2)  y = max(y-t, 15);
	else  y += 2*(115-y);
	return y;
}
int Sech(int id, int x)
{
	int win, lose, done, temp;
	if(dp[id][x]<=1)
		return dp[id][x];
	if(id==n+1)
	{
		if(x>=R)  return 1;
		if(x<=L)  return -1;
		return 0;
	}
	win = lose = done = 0;
	if(id%2)			//先手,想造出GoodEnding
	{
		if(s[id].x!=0)
		{
			temp = Sech(id+1, Go(1, x, s[id].x));
			if(temp==1)  win = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  lose = 1;
		}
		if(s[id].y!=0)
		{
			temp = Sech(id+1, Go(2, x, s[id].y));
			if(temp==1)  win = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  lose = 1;
		}
		if(s[id].z!=0)
		{
			temp = Sech(id+1, Go(3, x));
			if(temp==1)  win = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  lose = 1;
		}
		if(win)  return dp[id][x] = 1;
		else if(done)  return dp[id][x] = 0;
		else  return dp[id][x] = -1;
	}
	else
	{
		if(s[id].x!=0)
		{
			temp = Sech(id+1, Go(1, x, s[id].x));
			if(temp==1)  lose = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  win = 1;
		}
		if(s[id].y!=0)
		{
			temp = Sech(id+1, Go(2, x, s[id].y));
			if(temp==1)  lose = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  win = 1;
		}
		if(s[id].z!=0)
		{
			temp = Sech(id+1, Go(3, x));
			if(temp==1)  lose = 1;
			if(temp==0)  done = 1;
			if(temp==-1)  win = 1;
		}
		if(win)  return dp[id][x] = -1;
		else if(done)  return dp[id][x] = 0;
		else  return dp[id][x] = 1;
	}
}
int main(void)
{
	int ans, m, i;
	scanf("%d%d%d%d", &n, &m, &R, &L);
	R += 115, L += 115;
	for(i=1;i<=n;i++)
		scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].z);
	memset(dp, 62, sizeof(dp));
	ans = Sech(1, m+115);
	if(ans==1)
		printf("Good Ending\n");
	else if(ans==-1)
		printf("Bad Ending\n");
	else
		printf("Normal Ending\n");
	return 0;
}
/*
0 -5 8 -4
*/

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值