Time Limit: 1 Sec Memory Limit: MB
Submit: Solved: 19
[Submit] [Status] [Web Board] Description
Input
There'll is at the most test cases. Each case contains a command sequence with no more than characters.
Output
For each test case, print the case number, followed by Minimal/maximal possible x (in this order), and then the Minimal/maxima L Possible y.
Sample Input
F? FL?? Lfffrf
Sample Output
Case 1:1 3-1 1Case 2:-1 1 0 2Case 3:1 1 3 3
HINT
Source
The tenth session of Hunan Province College students computer Program design Contest
This question ... I wouldn't have DP.
That's about it. Dp[pos][dir]: At POS This position, when facing Dir, can give up to the four limits of how much
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace Std;bool vis[int (1e4) +10][4];struct node{int Xmin,xmax,ymin,ymax;} Dp[int (1e4) +10][4];int Goal;char s[int (1e4) +10];node dfs (int pos,int dir) {if (Vis[pos][dir]) return dp[pos][dir];vis[ Pos][dir]=1;dp[pos][dir].xmin=dp[pos][dir].xmax=dp[pos][dir].ymin=dp[pos][dir].ymax=0;if (pos==goal) {if (s[pos]= ='?') {if (dir==0) Dp[pos][dir].ymax=1;else if (dir==1) Dp[pos][dir].ymin=-1;else if (dir==2) dp[pos][dir].xmin=-1;elsedp[ Pos][dir].xmax=1;} else if (s[pos]== ' F ') {if (dir==0) Dp[pos][dir].ymin=dp[pos][dir].ymax=1;else if (dir==1) dp[pos][dir].ymin=dp[pos][ Dir].ymax=-1;else if (dir==2) Dp[pos][dir].xmin=dp[pos][dir].xmax=-1;elsedp[pos][dir].xmin=dp[pos][dir].xmax=1;}} Else{if (s[pos]== ' L ') {if (dir==0) Dp[pos][dir]=dfs (pos+1,2), else if (dir==1) Dp[pos][dir]=dfs (pos+1,3), else if (dir==2 ) Dp[pos][dir]=dfs (pos+1,1); Elsedp[pos][dir]=dfs (pos+1,0);} else if (s[pos]== ' R ') {if (dir==0) Dp[pos][dir]=dfs (pos+1,3), else if (dir==1) Dp[pos][dir]=dfs (pos+1,2); else if (dir==2) Dp[pos][dir]=dfs (pos+1,0); Elsedp[pos][dir]=dfs (pos+1,1);} else if (s[pos]== ' F ') {Dp[pos][dir]=dfs (Pos+1,dir); if (dir==0) {dp[pos][dir].ymin++;dp [pos][dir].ymax++;} else if (dir==1) {dp[pos][dir].ymin--;dp [pos][dir].ymax--;} else if (dir==2) {dp[pos][dir].xmin--;dp [pos][dir].xmax--;} else{dp[pos][dir].xmin++;DP [pos][dir].xmax++;}} Else{node One,two,three;three=dfs (Pos+1,dir); if (dir==0) {One=dfs (pos+1,2); Two=dfs (pos+1,3); three.ymin++; three.ymax++;} else if (dir==1) {One=dfs (pos+1,3); Two=dfs (pos+1,2); three.ymin--;three.ymax--;} else if (dir==2) {One=dfs (pos+1,1); Two=dfs (pos+1,0); three.xmin--;three.xmax--;} Else{one=dfs (pos+1,0); Two=dfs (pos+1,1); three.xmin++;three.xmax++;} Dp[pos][dir].xmin=min (min (one.xmin,two.xmin), three. xmin);DP [Pos][dir].xmax=max (Max (One.xmax,two.xmax), Three.xmax);DP [Pos][dir].ymin=min (Min (one.ymin,two.ymin), three.ymin);DP [Pos][dir].ymax=max (Max (One.ymax,two.ymax), Three.ymax);}} return Dp[pos][dir];} int main () {int cs=0;while (scanf ("%s", s)!=eof) {Goal=strlen (s) -1;memset (vis,0,sizeof (VIS)), node Ans=dfs (0,3);p rintf ("Case%d:%d%d%d%d\n", ++cs,ans.xmin,ans.xmax,ans.ymin,ans.ymax);}}
Csu1510:happy Robot