Hdu 1035 Robot Motion (dfs)

Source: Internet
Author: User

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); elseprintf ("% 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 ;}

 

Related Article

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.