HDU 1035 robot motion (DFS)

Source: Internet
Author: User

Despite this, I am very disappointed !!!

Come on !!! Come on !!!

"《《《《《《《《《《《《《

"

A very simple question, step by step. Going out of the matrix indicates that there is no ring. If you go to a place that has already passed, it indicates that there is a ring. You can output the result in the format !!!

# Include <stdio. h>

# Include <string. h>

Int n, m, temp;
Int ans [1010] [1010];
Char map [1010] [1010];

Void DFS (INT Sx, int SY)
{

While (SX> = 0 & SX <n & Sy> = 0 & Sy <M & map [SX] [sy]! = 'O ')
{
If (Map [SX] [sy] ='s ')
{

// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
SX ++;
}
Else if (Map [SX] [sy] = 'n ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
SX --;
}
Else if (Map [SX] [sy] = 'E ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
Sy ++;
}
Else if (Map [SX] [sy] = 'W ')
{
// Temp ++;
Map [SX] [sy] = 'O ';
Ans [SX] [sy] = ++ temp;
Sy --;
}
}
If (Map [SX] [sy] = 'O ')
Printf ("% d step (s) before a loop of % d step (s) \ n", ANS [SX] [sy]-1, temp-ans [SX] [sy] + 1 );
Else
Printf ("% d step (s) to exit \ n", temp );
}
Int main ()
{
Int K, I;
While (scanf ("% d", & N, & M, & K), N + M + k)
{
Memset (ANS, 0, sizeof (ANS ));
For (I = 0; I <n; I ++)
Scanf ("% s", map [I]);
Temp = 0;
DFS (0, k-1 );
}
Return 0;
}
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1035

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.