標籤:style blog color os 資料 2014
NASSA的機器人降落到了火星,降落的地方可以用X-Y座標表示。機器人最開始在(0, 0)。由於傳輸問題,部分指令可能會混淆,現在給出確定的命令與未知命令,請幫忙確認機器人的X、Y座標最小最大值分別是多少。
輸出格式為:
X最小 Y最小 X最大 Y最大
類比一下資料就能明白,走到的位置和命令執行順序沒有關係。
例如:RLL與RLR走到的位置都是一樣的。
因此,只要統計一下指令就好了。因為RL是一對相反的指令,UD是一對相反的指令。所以相減就能得到除不確定 指令外的最終位置。而不確定的命令在極端情況下可能全是RLUD四條命令中的任意一個。所以用最終位置的座標加減不確定命令的數量就可以得到所要求的值。
下面附上代碼:
/* * Problem: F * Date: 2014-7-20 * Author: Wuhen*/#include <map>#include <list>#include <queue>#include <string>#include <vector>#include <cstdarg>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#define LL long long#define Clean(a) memset(a, 0, sizeof(a))using namespace std;int main(){ int T; cin >> T; while(T--) { int x, y, n; x = y = n = 0; string s; cin >> s; for (int i = 0; i < s.size(); i++) switch(s[i]) { case ‘U‘: y += 1; break; case ‘D‘: y -= 1; break; case ‘L‘: x -= 1; break; case ‘R‘: x += 1; break; case ‘?‘: n += 1; break; } printf("%d %d %d %d\n", x-n, y-n, x+n, y+n); } return 0;}