poj 2632Crashing Robots

来源:互联网 发布:达芬奇恶魔知乎 编辑:程序博客网 时间:2024/05/16 07:16

水的一比。。。 不过,看discuss 想说:这和想:这和有关系吗? 只要按照自己所制定的规则走下去好了。。

不过写了320 行,一个小时(顺便重刷了高达uc,开心)。。

复制啊复制。。。

#include<cstdio>#include<cstring>#include<iostream>#include<string>#include<iostream>using namespace std;struct node{    char dir;    int x;    int y;    int num;}me[110*110];struct sb{    int have;    int num;}way[110][110];int n,m;int who1;int who2;int judgee(int who,int x1,int y1,int step,int max1){    way[x1][y1].have=0;    for(int i=x1+1;i<=min(x1+step,max1);i++)    {        if(way[i][y1].have)        {            //cout<<"Robot "<<who<<" crashes into robot "<<way[i][y1].num<<endl;            who1=who;            who2=way[i][y1].num;            way[i][y1].have=0;            return 1;        }    }    if(x1+step>max1)    {        //cout<<"Robot "<<who<<" crashes into the wall"<<endl;        who1=who;        return 2;    }    way[x1+step][y1].num=who;    way[x1+step][y1].have=1;    //cout<<"OK"<<endl;    me[who].x=x1+step;    me[who].y=y1;    return 0;}int judgew(int who,int x1,int y1,int step,int min1){    way[x1][y1].have=0;    for(int i=x1;i>=max(min1,x1-step);i--)    {        if(way[i][y1].have)        {            //cout<<"Robot "<<who<<" crashes into robot "<<way[i][y1].num<<endl;            way[i][y1].have=0;            who1=who;            who2=way[i][y1].num;            return 1;        }    }    if(x1-step<min1)    {        //cout<<"Robot "<<who<<" crashes into the wall"<<endl;        who1=who;        return 2;    }    way[x1-step][y1].num=who;    way[x1-step][y1].have=1;    me[who].x=x1-step;    me[who].y=y1;    //cout<<"OK"<<endl;    return 0;}int judges(int who,int x1,int y1,int step,int min1){    way[x1][y1].have=0;    for(int i=y1;i>=max(min1,y1-step);i--)    {        if(way[x1][i].have)        {            //cout<<"Robot "<<who<<" crashes into robot "<<way[x1][i].num<<endl;            way[x1][i].have=0;            who1=who;            who2=way[x1][i].num;            return 1;        }    }    if(y1-step<min1)    {        //cout<<"Robot "<<who<<" crashes into the wall"<<endl;        who1=who;        return 2;    }    way[x1][y1-step].num=who;    way[x1][y1-step].have=1;    //cout<<"OK"<<endl;    me[who].x=x1;    me[who].y=y1-step;    return 0;}int judgen(int who,int x1,int y1,int step,int max1){    way[x1][y1].have=0;    for(int i=y1+1;i<=min(y1+step,max1);i++)    {        if(way[x1][i].have)        {            //cout<<"Robot "<<who<<" crashes into robot "<<way[x1][i].num<<endl;            way[x1][i].have=0;            who1=who;            who2=way[x1][i].num;            return 1;        }    }    if(y1+step>max1)    {        //cout<<"Robot "<<who<<" crashes into the wall"<<endl;        who1=who;        return 2;    }    way[x1][y1+step].num=who;    way[x1][y1+step].have=1;    me[who].x=x1;    me[who].y=y1+step;    //cout<<"OK"<<endl;    return 0;}int main(){    int T;    cin>>T;    while(T--)    {        cin>>n>>m;        for(int i=1;i<=max(n,m);i++)            for(int j=1;j<=max(n,m);j++)            {                way[i][j].have=0;            }        int a,b;        cin>>a>>b;        int x,y;        char d;        for(int i=1;i<=a;i++)        {            cin>>x>>y>>d;            me[i].x=x;            me[i].y=y;            me[i].num=i;            me[i].dir=d;            way[x][y].have=1;            way[x][y].num=i;        }        int who,step;        char how;        int ok=0;        for(int i=1;i<=b;i++)        {            cin>>who>>how>>step;            if(ok)                continue;            if(how=='F')            {                if(me[who].dir=='E')                {                    ok=judgee(who,me[who].x,me[who].y,step,n);                }                else if(me[who].dir=='W')                {                    ok=judgew(who,me[who].x,me[who].y,step,1);                }                else if(me[who].dir=='N')                {                    ok=judgen(who,me[who].x,me[who].y,step,m);                }                else                {                    ok=judges(who,me[who].x,me[who].y,step,1);                }            }            else if(how=='L')            {                int fin=step%4;                if(fin==1)                {                    if(me[who].dir=='E')                    {                        me[who].dir='N';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='W';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='S';                    }                    else                    {                        me[who].dir='E';                    }                }                else if(fin==2)                {                    if(me[who].dir=='E')                    {                        me[who].dir='W';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='S';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='E';                    }                    else                    {                        me[who].dir='S';                    }                }                else if(fin==3)                {                    if(me[who].dir=='E')                    {                        me[who].dir='S';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='E';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='N';                    }                    else                    {                        me[who].dir='W';                    }                }            }            else if(how=='R')            {                int fin=step%4;                if(fin==3)                {                    if(me[who].dir=='E')                    {                        me[who].dir='N';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='W';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='S';                    }                    else                    {                        me[who].dir='E';                    }                }                else if(fin==2)                {                    if(me[who].dir=='E')                    {                        me[who].dir='W';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='S';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='E';                    }                    else                    {                        me[who].dir='S';                    }                }                else if(fin==1)                {                    if(me[who].dir=='E')                    {                        me[who].dir='S';                    }                    else if(me[who].dir=='N')                    {                        me[who].dir='E';                    }                    else if(me[who].dir=='W')                    {                        me[who].dir='N';                    }                    else                    {                        me[who].dir='W';                    }                }            }        }        if(ok==1)        {            cout<<"Robot "<<who1<<" crashes into robot "<<who2<<endl;        }        else if(ok==2)        {            cout<<"Robot "<<who1<<" crashes into the wall"<<endl;        }        else        {            cout<<"OK"<<endl;        }    }    return 0;}
0 0