TA的每日心情 | 慵懶 2015-4-10 14:18 |
---|
簽到天數: 78 天 [LV.6]常住居民II
管理員
- 積分
- 3959
|
趕快加入我們來參與討論吧!
您需要 登錄 才可以下載或查看,沒有帳號?加入我們
x
原文: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;
}
|
|