Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会RE呢???求指导啊

Posted by daojian at 2013-03-26 12:57:52 on Problem 3278
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
int i,j,n,k,minute,len[200000];
struct step
{
    int place;
    int minute;
};
step next,now;
queue<step>q;

void bfs(int n)
{
    int dir[3]={-1,1,n};
    now.place=n;
    now.minute=0;
    len[now.place]=0;
    while(!q.empty())
    q.pop();
    q.push(now);

    while(!q.empty())
    {
        now=q.front();

        q.pop();
        if(now.place==k)
        {
            cout<<now.minute<<endl;
            break;
        }
        for(i=0;i<3;i++)
        {

            if(len[now.place+dir[i]]>0)
            continue;
            if(now.place+dir[i]<n) continue;
            next.place=now.place+dir[i];
            next.minute=now.minute+1;

            len[next.place]=next.minute;
            q.push(next);
        }
    }

}
int main()
{
    freopen("in.txt","r",stdin);
    while(cin>>n>>k)
    {
        memset(len,0,sizeof(len));
        bfs(n);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator