1510:happy Robot
Time limit:1 Sec Memory limit:128 MB
submit:19 Solved:7
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
Problem solving: DP, the scene actually did not do it ... Too dumb to be able to.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <stack> - #defineLL Long Long - #definePII pair<int,int> the #defineINF 0x3f3f3f3f - using namespacestd; - Const intMAXN =1010; - CharCMD[MAXN]; + intdp[2][4]; - Const intdir[4][2] = {1,0,0,-1,-1,0,0,1};//Top right lower left upper + intMymax (intAintb) { A returnMax (A, b); at } - intMymin (intAintb) { - returnmin (A, b); - } - intGoint(*OP) (int,int),BOOLFlagintXinty) { - intCur =0; indp[0][0] =0; - for(inti =1; I <4; ++i) to if(flag) dp[0][i] =-INF; + Elsedp[0][i] =INF; - for(inti =0; Cmd[i]; ++i) { the for(intK =0; K <4; ++K) dp[cur^1][k] = flag?-Inf:inf; * if(Cmd[i] = ='F'|| Cmd[i] = ='?') { $dp[cur^1][0] = OP (dp[cur^1][0],dp[cur][0]+x);Panax Notoginsengdp[cur^1][1] = OP (dp[cur^1][1],dp[cur][1]-y); -dp[cur^1][2] = OP (dp[cur^1][2],dp[cur][2]-x); thedp[cur^1][3] = OP (dp[cur^1][3],dp[cur][3]+y); + } A if(Cmd[i] = ='L'|| Cmd[i] = ='?') { thedp[cur^1][0] = OP (dp[cur^1][0],dp[cur][1]); +dp[cur^1][1] = OP (dp[cur^1][1],dp[cur][2]); -dp[cur^1][2] = OP (dp[cur^1][2],dp[cur][3]); $dp[cur^1][3] = OP (dp[cur^1][3],dp[cur][0]); $ } - if(Cmd[i] = ='R'|| Cmd[i] = ='?') { -dp[cur^1][0] = OP (dp[cur^1][0],dp[cur][3]); thedp[cur^1][1] = OP (dp[cur^1][1],dp[cur][0]); -dp[cur^1][2] = OP (dp[cur^1][2],dp[cur][1]);Wuyidp[cur^1][3] = OP (dp[cur^1][3],dp[cur][2]); the } -Cur ^=1; Wu } - intAns = flag?-Inf:inf; About for(inti =0; I <4; ++i) $Ans =op (dp[cur][i],ans); - returnans; - } - intMain () { A intCS =1; + while(~SCANF ("%s", CMD)) { the intmax_x = Go (Mymax,true,1,0); - intmin_x = Go (mymin,false,1,0); $ intMax_y = Go (Mymax,true,0,1); the intmin_y = Go (mymin,false,0,1); theprintf"Case %d:%d %d%d%d\n", cs++, min_x,max_x,min_y,max_y); the } the return 0; -}
View Code
CSU 1510 Happy Robot