HDU 1458 BFS Template formulation

Source: Internet
Author: User

Background: 1. Compilation error: Next and system naming conflicts. 2.wa: The starting point is greater than the condition of the floor is not considered. Wawawa the afternoon, I took the way to set the content to 1, instead of the flag array to mark whether access is right. Then experiment and put the visited mark as-100000, also ac!!! Indicates that Ki exists less than 0 in the title!!!!! Presence -1!!!!! and test instructions!! WA had an afternoon ...

My Code:

#include <cstdio> #include <iostream> #include <cstring> #include <queue>using namespace std; int floor[299],n,e;struct state{int X,count;}     Now,next1;void BFS (state temp) {queue<state> q;     temp.count=0;     Q.push (temp);         while (!q.empty ()) {Now=q.front ();            if (now.x = = e) {printf ("%d\n", Now.count);         Return                 }else{if (floor[now.x]) {next1.x=now.x+floor[now.x]; if (next1.x >= 1 && next1.x <= n && floor[next1.x]!= -1000000) {next1.count=now.c                    ount+1;                 Q.push (NEXT1);                 }} if (floor[now.x]) {next1.x=now.x-floor[now.x]; if (next1.x >= 1 && next1.x <= n && floor[next1.x]! = -1000000) {next1.count=now.c                    ount+1;                 Q.push (NEXT1);    }} floor[now.x]=-1000000;         Q.pop ();     }} printf (" -1\n"); return;}        int main (void) {while (scanf ("%d", &n), N) {scanf ("%d%d", &now.x,&e);        memset (floor,-1000000,sizeof (floor));        for (int i=1;i <= n;i++) scanf ("%d", &floor[i]);        if (now.x < 1 | | now.x > N) printf (" -1\n");    else BFS (now); } return 0;}


HDU 1458 BFS Template formulation

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.