G - 曙色

http://acm.hnucm.edu.cn/vjudge/contest/view.action?cid=111#problem/G

Description

In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.


image

INPUT

The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
L: turn left 90 degrees,
R: turn right 90 degrees, or
F: move forward one meter,
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
Output one line for each test case:

OUT

Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.)
Robot i crashes into robot j, if robots i and j crash, and i is the moving robot.
OK, if no crashing occurs.
Only the first crash is to be reported.

Sample Input

4
5 4
2 2
1 1 E
5 4 W
1 F 7
2 F 7
5 4
2 4
1 1 E
5 4 W
1 F 3
2 F 1
1 L 1
1 F 3
5 4
2 2
1 1 E
5 4 W
1 L 96
1 F 2
5 4
2 3
1 1 E
5 4 W
1 F 4
1 L 1
1 F 20 

Sample Output

 Robot 1 crashes into the wall
Robot 1 crashes into robot 2
OK
Robot 1 crashes into robot 2 

AC代碼
面向?qū)ο笠淮蝍c恩溅,哈哈

#include<iostream>
#include<cstring>
#define qc std::ios::sync_with_stdio(false)
using namespace std;
const int maxl=1e2+10;
const int mod=1000000;
const string V="NWSE";
int t,X,Y,n1,n2,t1,t2;
bool isbreak=false;
int MAP[101][101];
struct mac
{
    int x,y;
    int v;
    void getv(char c,int *v){
        v[0]=v[1]=0;
        if(c=='W')v[0]=-1;
        if(c=='E')v[0]=1;
        if(c=='S')v[1]=-1;
        if(c=='N')v[1]=1;
    }
    void left(){
        if(v==3)v=0;
        else v++;
    }
    void right(){
        if(v==0)v=3;
        else v--;
    }
    void go(){
        int tv[2],mine=MAP[x][y];
        getv(V[v],tv);
        x+=tv[0];
        y+=tv[1];
        if(MAP[x][y]){
            if(!isbreak)printf("Robot %d crashes into robot %d\n",mine,MAP[x][y]);
            isbreak=true;
        }
        else if(x>X||y>Y||x<1||y<1){
            //printf("%d\n",isbreak);
            if(!isbreak)printf("Robot %d crashes into the wall\n",mine);
            isbreak=true;
        }
        else{
            MAP[x-tv[0]][y-tv[1]]=0;
            MAP[x][y]=mine;
        }
    }
};
mac ma[maxl];
char c;
int main(){
    qc;
    cin>>t;
    while (t--)
    {
        memset(MAP,0,sizeof(MAP));
        memset(ma,0,sizeof(ma));
        isbreak=false;
        cin>>X>>Y>>n1>>n2;
        for(int i=1;i<=n1;i++){
            cin>>ma[i].x>>ma[i].y>>c;
            ma[i].v=V.find(c);
            MAP[ma[i].x][ma[i].y]=i;
        }
        for(int i=1;i<=n2;i++){
            int *v;
            cin>>t1>>c>>t2;
            if(c=='L')while(t2--)ma[t1].left();
            if(c=='R')while(t2--)ma[t1].right();
            if(c=='F')while (t2--)ma[t1].go();
        }
        if(!isbreak)printf("OK\n");
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市也切,隨后出現(xiàn)的幾起案子辛萍,更是在濱河造成了極大的恐慌棱诱,老刑警劉巖臼疫,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件砰琢,死亡現(xiàn)場離奇詭異仰坦,居然都是意外死亡昆烁,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進(jìn)店門缎岗,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人白粉,你說我怎么就攤上這事传泊。” “怎么了鸭巴?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵眷细,是天一觀的道長。 經(jīng)常有香客問我鹃祖,道長溪椎,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任恬口,我火速辦了婚禮校读,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘祖能。我一直安慰自己歉秫,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布养铸。 她就那樣靜靜地躺著雁芙,像睡著了一般轧膘。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上兔甘,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天谎碍,我揣著相機(jī)與錄音,去河邊找鬼洞焙。 笑死蟆淀,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的闽晦。 我是一名探鬼主播扳碍,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼仙蛉!你這毒婦竟也來了笋敞?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤荠瘪,失蹤者是張志新(化名)和其女友劉穎夯巷,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哀墓,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡趁餐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了篮绰。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片后雷。...
    茶點(diǎn)故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖吠各,靈堂內(nèi)的尸體忽然破棺而出臀突,到底是詐尸還是另有隱情,我是刑警寧澤贾漏,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布候学,位于F島的核電站,受9級特大地震影響纵散,放射性物質(zhì)發(fā)生泄漏梳码。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一伍掀、第九天 我趴在偏房一處隱蔽的房頂上張望掰茶。 院中可真熱鬧,春花似錦蜜笤、人聲如沸符匾。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽啊胶。三九已至甸各,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間焰坪,已是汗流浹背趣倾。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留某饰,地道東北人儒恋。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像黔漂,于是被迫代替她去往敵國和親诫尽。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內(nèi)容