ACM-ICPC 2018 徐州赛区网络预赛 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

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

题目大意:

给出一个初始值,n轮操作,一个k一个l值。每轮操作有三种选择,一为加上一个值,二为减去一个值,三为使之成为一个负值。每一轮于该轮的玩家都可以在三个选择中选一个进行执行。

一个值经过了n轮的操作假如>=k则进入一个good ending,假如<=l则进入一个bad ending,假如都不是,则进入一个normal ending。每局比赛中都有一个的先手者总是想要达到一个good ending ,后手者总是想要达到一个bad ending。

思路:

首先需要注意的是,每个玩家首先需要注意能否阻止对方达到目的以及能否达到自己的目的,假如又不能达到自己的目的,又可以组织对方的目的则进入一个bad ending。

然后来判断能否阻止或者达到某个目的。这就是从最后开始向前推导,给出需要判断的区间,向前判断,从-100到100这些数中进行判断,看其经过操作是否存在于下一轮可以达到可以达到目标区间的数集中。假如这个人对于这个区间的态度是阻止,那么需要三种操作都不能进入目标数集才认为这个数是可行的,假如这个人对于这个区间的态度是渴望的,那么只要三种操作中的任意一种可以达到目标数集就可以。

//双方的目标都是到达自己想要的结局
//假如一方的目的无法达到时总是先看能否组织对方达到目的
//假如两个人想要到达的目的都达不到,那么就是normal
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int op[3][1005];
map<int,bool> okey[2];
int val;
int check(int which_op,int num,int loop)
{
	if(op[which_op][loop]==0) return -1;
	int last=(loop+1)%2;
	if(which_op==0)
	{
		if(okey[last].count(min(num+op[which_op][loop],100))) return 1;
	}
	else if(which_op==1)
	{
		if(okey[last].count(max(num-op[which_op][loop],-100))) return 1;
	}
	else
	{
		if(okey[last].count(-num)) return 1;
	}
	return 0;
}
bool add(int loop,bool obj)
{
	int now=loop%2;
	int last=(loop+1)%2;
	for(int i=-100;i<=100;i++)
	{
		if(!obj)//假使这一轮是妨碍轮
		{
			if(check(0,i,loop)!=0&&check(1,i,loop)!=0&&check(2,i,loop)!=0) okey[now][i]=1;
		}
		else//假使这一轮是促进轮
		{
			if(check(0,i,loop)==1||check(1,i,loop)==1||check(2,i,loop)==1) okey[now][i]=1;
		}
	}
	okey[last].clear();
}
bool solve(int l,int r,int ring,int Ty)
{
	okey[0].clear(),okey[1].clear();
	for(int i=l;i<=r;i++) okey[(ring+1)%2][i]=1;
	for(int i=ring;i>=1;i--)
	{
		add(i,(i%2)==Ty);
	}
	return okey[1].count(val);
}
int main()
{
	int n,l,k;
	while(~scanf("%d%d%d%d",&n,&val,&k,&l))
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&op[0][i],&op[1][i],&op[2][i]);
		}
		if(solve(k,100,n,1)){
			cout<<"Good Ending"<<endl;
		}
		else if(solve(-100,l,n,0))
		{
			cout<<"Bad Ending"<<endl;
		}
		else
		{
			cout<<"Normal Ending"<<endl;
		}
	}
}

猜你喜欢

转载自blog.csdn.net/baiyifeifei/article/details/82622198