码迷,mamicode.com
首页 > 其他好文 > 详细

徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

时间:2018-09-21 10:46:32      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:only   display   desc   icp   for   msu   ace   stream   ora   

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?8Note 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 kkll 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,l1\le n \le 10001n1000-100 \le m \le 100?100m100 , -100 \le l < k \le 100?100l<k100), 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,ca\ge 0a0 , b\ge0b0 ,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 bbc=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?1It 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 徐州赛区网络预赛

题意:

两个人玩游戏 初始分值是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表示先手必败

根据递归返回的结果 加上当前的局数来判断当前结果

  1 #include <iostream>
  2 #include <algorithm>
  3 #include <stdio.h>
  4 #include <vector>
  5 #include <cmath>
  6 #include <cstring>
  7 #include <set>
  8 #include <map>
  9 
 10 #define inf 0x3f3f3f3f
 11 using namespace std;
 12 
 13 typedef long long LL;
 14 
 15 int n, m, l, k;
 16 const int maxn = 1005;
 17 int dp[maxn][205];
 18 struct node{
 19     int a, b, c;
 20 }op[maxn];
 21 
 22 int solve(int id, int x)
 23 {
 24     int win, lose, done, tmp;
 25     if(dp[id][x] <= 1){
 26         return dp[id][x];
 27     }
 28     if(id == n + 1){
 29         if(x >= k) return 1;
 30         if(x <= l) return -1;
 31         return 0;
 32     }
 33 
 34     win = lose = done = 0;
 35     if(id % 2){
 36         if(op[id].a != 0){
 37             tmp = solve(id + 1, min(x + op[id].a, 200));
 38             if(tmp == 1){
 39                 win = 1;
 40             }
 41             if(tmp == 0){
 42                 done = 1;
 43             }
 44             if(tmp == -1){
 45                 lose = 1;
 46             }
 47         }
 48         if(op[id].b != 0){
 49             tmp = solve(id + 1, max(0, x - op[id].b));
 50             if(tmp == 1){
 51                 win = 1;
 52             }
 53             if(tmp == 0){
 54                 done = 1;
 55             }
 56             if(tmp == -1){
 57                 lose = 1;
 58             }
 59         }
 60         if(op[id].c != 0){
 61             tmp = solve(id + 1, 200 - x);
 62             if(tmp == 1){
 63                 win = 1;
 64             }
 65             if(tmp == 0){
 66                 done = 1;
 67             }
 68             if(tmp == -1){
 69                 lose = 1;
 70             }
 71         }
 72         if(win == 1){
 73             return dp[id][x] = 1;
 74         }
 75         else if(done == 1){
 76             return dp[id][x] = 0;
 77         }
 78         else{
 79             return dp[id][x] = -1;
 80         }
 81     }
 82     else{
 83         if(op[id].a != 0){
 84             tmp = solve(id + 1, min(x + op[id].a, 200));
 85             if(tmp == 1){
 86                 lose = 1;
 87             }
 88             if(tmp == 0){
 89                 done = 1;
 90             }
 91             if(tmp == -1){
 92                 win = 1;
 93             }
 94         }
 95         if(op[id].b != 0){
 96             tmp = solve(id + 1, max(0, x - op[id].b));
 97             if(tmp == 1){
 98                 lose = 1;
 99             }
100             if(tmp == 0){
101                 done = 1;
102             }
103             if(tmp == -1){
104                 win = 1;
105             }
106         }
107         if(op[id].c != 0){
108             tmp = solve(id + 1, 200 - x);
109             if(tmp == 1){
110                 lose = 1;
111             }
112             if(tmp == 0){
113                 done = 1;
114             }
115             if(tmp == -1){
116                 win = 1;
117             }
118         }
119         if(win == 1){
120             return dp[id][x] = -1;
121         }
122         else if(done == 1){
123             return dp[id][x] = 0;
124         }
125         else{
126             return dp[id][x] = 1;
127         }
128     }
129 
130 }
131 
132 int main()
133 {
134     while(scanf("%d%d%d%d", &n, &m, &k, &l) != EOF){
135         m += 100;
136         l += 100;
137         k += 100;
138         for(int i = 1; i <= n; i++){
139             scanf("%d%d%d", &op[i].a, &op[i].b, &op[i].c);
140         }
141 
142         //memset(dp, 62, sizeof(dp));
143         //cout<<dp[0]<<endl;
144         memset(dp, inf, sizeof(dp));
145         int ans = solve(1, m);
146         if(ans == 1){
147             printf("Good Ending\n");
148         }
149         else if(ans == -1){
150             printf("Bad Ending\n");
151         }
152         else{
153             printf("Normal Ending\n");
154         }
155     }
156     return 0;
157 }

 

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?8Note 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 kkll 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,l1\le n \le 10001n1000-100 \le m \le 100?100m100 , -100 \le l < k \le 100?100l<k100), 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,ca\ge 0a0 , b\ge0b0 ,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 bbc=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?1It 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 徐州赛区网络预赛

徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

标签:only   display   desc   icp   for   msu   ace   stream   ora   

原文地址:https://www.cnblogs.com/wyboooo/p/9684822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!