栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2803 Crashing Robots

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2803 Crashing Robots

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int A, B, n, m;struct robot{    int x, y, dir;}a[105];bool judge(int k) {    if(a[k].x <= 0 || a[k].x > A || a[k].y <= 0 || a[k].y > B)    {        printf("Robot %d crashes into the walln",k);        return true;    }    for(int i = 1; i <= n; i++)    {        if(i == k) continue;        if(a[k].x == a[i].x && a[k].y == a[i].y)        { printf("Robot %d crashes into robot %dn",k,i); return true;        }    }    return false;}int main(){    int T, i, j;    char ch;    scanf("%d",&T);    while(T--)    {        scanf("%d%d%d%d",&A, &B, &n, &m);        for(i = 1; i <= n; i++)        { scanf("%d %d %c",&a[i].x, &a[i].y, &ch); if(ch == 'E')     a[i].dir = 0; else if(ch == 'S')     a[i].dir = 1; else if(ch == 'W')     a[i].dir = 2; else if(ch == 'N')     a[i].dir = 3;        }        bool flag = false;        int num, cnt;        for(i = 0; i < m; i++)        { scanf("%d %c %d",&num, &ch, &cnt); if(ch == 'F') {     if(!flag)     {         for(j = 0; j < cnt; j++)         {  if(a[num].dir == 0)      a[num].x++;  else if(a[num].dir == 1)      a[num].y--;  else if(a[num].dir == 2)      a[num].x--;  else if(a[num].dir == 3)      a[num].y++;  flag = judge(num);  if(flag)      break;         }     } } else if(ch == 'L')     a[num].dir = (a[num].dir - cnt % 4 + 4) % 4; else if(ch == 'R')     a[num].dir = (a[num].dir + cnt % 4) % 4;        }        if(!flag) printf("OKn");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379587.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号