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

啊啊啊 为什么自己测试的对却一直WA! 用的G++

Posted by yiyirou at 2012-09-03 15:26:09 on Problem 3278
#include<stdio.h> 
#include<queue>
#include<string.h> 
using namespace std;

typedef struct Node
{int x;
 int sum;
 }Node;
 int m,n;
 int flag[200000];
 
 int BFS()
 {Node p,q;
  queue<Node> qu;
  p.x=m;
  p.sum=0;
  qu.push(p);
  while(!qu.empty())
  { p=qu.front();
    qu.pop();
    if(m==n) return 0;
    if(p.x==n) return p.sum;
    p.sum++;
    q=p;
    q.x=q.x*2;
    if(q.x>=0&&q.x<=100000&&flag[q.x]){flag[q.x]=0;
       qu.push(q);}
    q=p;
    q.x--;
    if(q.x>=0&&q.x<=100000&&flag[q.x]) {flag[q.x]=0;qu.push(q);}
    q=p;
    q.x++;
    if(q.x>=0&&q.x<=100000&&flag[q.x])   { flag[q.x]=0; qu.push(q);}
  
    }
  }
 
 main()
 {int a;
 while(scanf("%d%d",&m,&n)!=EOF)
  {memset(flag,1,sizeof(flag));
  a=BFS();
  printf("%d\n",a);} 
  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