NASSA’s Robot

來源:互聯網
上載者:User

標籤: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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.