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

zoj 1708 Robot Motion

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

zoj 1708 Robot Motion

#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 1000typedef struct{    int to,next,cap;} E;E edge[N*N];int V[N];int p[N];int M;void insert(int from,int to){    edge[M].to=to;    edge[M].cap=1;    edge[M].next=V[from];    V[from]=M++;}int main(){    int n,m,s,i,j;    char str[N][N],c;    while(scanf("%d%d",&n,&m))    {        if(n==0&&m==0)break;        scanf("%dn",&s);        M=1;        memset(V,-1,sizeof(V));        for(i=1; i<=n; i++)        { for(j=1; j<=m ; j++) {     scanf("%c",&str[i][j]); } getchar();        }        i=1;        while(1)        { c=str[i][s]; if(V[i]==-1) { insert(i,s); } else {     for(j=V[i]; j+1; j=edge[j].next)     if(edge[j].to==s)     {         break;     }     if(!(j+1))     insert(i,s);     else break; } switch(c) { case 'N':     i-=1;     break; case 'W':     s-=1;     break; case 'E':     s+=1;     break; case 'S':     i+=1;     break; } if(s>m||i>n||!i||!s)break;        }        if(!i||!s||i>n||s>m)        printf("%d step(s) to exitn",M-1);        else        { printf("%d step(s) before a loop of %d step(s)n",j-1,M-j);        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372937.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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