竹園論壇

標題: a314 - C 導覽型機器人 [打印本頁]

作者: Sylveon    時間: 2014-4-27 11:35
標題: a314 - C 導覽型機器人
原文:http://zerojudge.tw/ShowProblem?problemid=a314
AC   :http://zerojudge.tw/Submissions? ... mp;account=lfs92002
ACCODE:http://ideone.com/LbK2T2
懷舊系列,國中時寫的code。模擬題,有點無言的走路方法,就照做就好

/**********************************************************************************/
/*  Problem: a314 "C 導覽型機器人" from 2011 NPSC 國中組初賽           */
/*  Language: CPP (1296 Bytes)                                                    */
/*  Result: AC(4ms, 376KB) judge by this@ZeroJudge                                */
/*  Author: lfs92002 at 2011-12-06 12:34:06                                       */
/**********************************************************************************/


#include<iostream>
using namespace std;
int main()
{
        int T;
        short map[12][12],h,w,x,y;
        short start_x,start_y,sum,tx,ty,n,tn;
        bool _b;
        cin>>T;
        while(T--)
        {
                for(y=0;y<=11;y++)
                        for(x=0;x<=11;x++)
                                map[y][x]=-1;
                cin>>h>>w;
                for(y=1;y<=h;y++)
                        for(x=1;x<=w;x++)
                                cin>>map[y][x];
                for(y=1;y<=h;y++)//Find 0
                {
                        for(x=1;x<=w;x++)
                                if(map[y][x]==0)
                                {
                                        start_x=x;
                                        start_y=y;
                                }
                }
                _b=true;
                n=1;tn=0;//tn 步
                while(_b)
                {
                        if(map[start_y-1][start_x]==n)//UP
                        {
                                tn=0;
                                while(map[start_y-1][start_x]==n)
                                {
                                        start_y--;
                                        tn++;
                                        n++;
                                }
                                cout<<'N'<<tn;

                        }
                        else if(map[start_y+1][start_x]==n)//DOWN
                        {
                                tn=0;
                                while(map[start_y+1][start_x]==n)
                                {
                                        start_y++;
                                        tn++;
                                        n++;
                                }
                                cout<<'S'<<tn;
                        }
                        else if(map[start_y][start_x+1]==n)//RIGHT
                        {
                                tn=0;
                                while(map[start_y][start_x+1]==n)
                                {
                                        start_x++;
                                        tn++;
                                        n++;
                                }
                                cout<<'E'<<tn;
                        }
                        else if(map[start_y][start_x-1]==n)//RIGHT
                        {
                                tn=0;
                                while(map[start_y][start_x-1]==n)
                                {
                                        start_x--;
                                        tn++;
                                        n++;
                                }
                                cout<<'W'<<tn;
                        }
                        else
                        {
                                _b=false;
                        }
                }
                cout<<endl;
        }
        return 0;
}





歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2