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-3options, 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 .
That is, if there are three options in a selection, the score will be increased by 1, decreased by 1, or multiplied by −1. The score before the selection is 8. 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 100 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,l( 10001≤n≤1000, −100≤m≤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≥0 ,b≥0 ,c=0 or c=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
题目来源
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <queue> 7 #include <stack> 8 #include <cstdlib> 9 #include <iomanip> 10 #include <cmath> 11 #include <cassert> 12 #include <ctime> 13 #include <map> 14 #include <set> 15 #include <vector> 16 using namespace std; 17 #define ull unsigned long long 18 #define ll long long 19 #define ph push_back 20 int n,m,l,r; 21 #define N 1009 22 int a[N],b[N],c[N]; 23 map<int,map<int,int> >mp; 24 void init() 25 { 26 for(int i=0;i<N;i++) 27 { 28 for(int j=-120;j<120;j++)//-120到120 29 { 30 mp[i][j]=-1;//要小于0 31 } 32 } 33 } 34 //先手想要最后的结果尽量大,而后手希望最后的结果尽量小 35 int dfs(int cnt,int now){//cnt 次数,now 当前的得分 36 if(cnt>=n+1){ 37 if(now>=r) return 2; 38 if(now>l) return 1; 39 return 0; 40 } 41 if(mp[cnt][now]!=-1) return mp[cnt][now]; 42 if(cnt&1){ 43 int val=0; 44 if(a[cnt]) val=max(val,dfs(cnt+1,min(100,now+a[cnt])) ); 45 if(b[cnt]) val=max(val,dfs(cnt+1,max(-100,now-b[cnt])) ); 46 if(c[cnt]) val=max(val,dfs(cnt+1,-now)); 47 return mp[cnt][now]=val; 48 } 49 else{ 50 int val=2; 51 if(a[cnt]) val=min(val,dfs(cnt+1,min(100,now+a[cnt])) ); 52 if(b[cnt]) val=min(val,dfs(cnt+1,max(-100,now-b[cnt])) ); 53 if(c[cnt]) val=min(val,dfs(cnt+1,-now) ); 54 return mp[cnt][now]=val; 55 } 56 } 57 int main() 58 { 59 scanf("%d%d%d%d",&n,&m,&r,&l);//刚开始输成了l,r. 60 for(int i=1;i<=n;i++)//要从1开始 61 { 62 scanf("%d%d%d",&a[i],&b[i],&c[i]); 63 } 64 init(); 65 int val=dfs(1,m); 66 if(val==2){ 67 printf("Good Ending\n"); 68 } 69 else if(val==1){ 70 printf("Normal Ending\n"); 71 } 72 else{ 73 printf("Bad Ending\n"); 74 } 75 return 0; 76 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现