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

我想知道为什么G++能AC,改用C++却WA了!!!很无语= =

Posted by 541507120156 at 2016-09-27 14:00:28 on Problem 3278
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define N 100010
#define INF 2>>30
using namespace std;
int d[N],b[N];
int n,k;
queue<int>q;
int BFS()
{
    int i,t,h,flag;
    q.push(n);
    b[n]=0;
    flag=0;
    while(!q.empty())
    {
        h=q.front();
        q.pop();
        for(i=0;i<3;i++)
        {
            if(i==0)
                t=h-1;
            if(i==1)
                t=h+1;
            if(i==2)
                t=h*2;
            if(t<0||t>N)
                continue;
            if(d[t]==INF)
            {
                d[t]=d[h]+1;
                q.push(t);
            }
            if(t==k)
            {
                flag=1;
                break;
            }
        }
        if(flag)
            break;
    }
    return d[k];
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        fill(d,d+N,INF);
        int hh=BFS();
        if(n>=k)
            printf("%d\n",n-k);
        else
            printf("%d\n",hh);
    }
    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