HDU 1035 robot motion (large simulation)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1035

It indicates that this question is very simple and basically there is no trap. As for WA, I did not set the start point to 1 twice, that is, I added 1 more to the start point.

# Include <iostream> # include <string. h> # include <stdio. h> using namespace STD; # define maxn 20int map [maxn] [maxn]; char rec [maxn] [maxn]; int find_ans (INT t) {int I = 1, j = T, step = 1; if (REC [I] [J] = 0) {printf ("% d step (s) to exit \ n", 0 ); return 0;} map [I] [J] = 1; while (1) {Switch (REC [I] [J]) {Case 'N': I --; break; case's ': I ++; break; Case 'E': J ++; break; Case 'W': J --; break;} Step ++; if (Map [I] [J]> 0) {printf ("% d step (s) before a loop of % d step (s) \ n ", map [I] [J]-1, step-map [I] [J]); Return 0;} If (REC [I] [J] = 0) {printf ("% d step (s) to exit \ n", step-1); Return 0;} else map [I] [J] = step ;} return 0;} int main () {int n, m, T, I; while (scanf ("% d", & N, & M )) {If (n = 0 & M = 0) return 0; scanf ("% d", & T); memset (MAP, 0, sizeof (MAP )); memset (REC, 0, sizeof (REC); for (I = 1; I <= N; I ++) scanf ("% s ", REC [I] + 1); find_ans (t);} return 0 ;}

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.