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

大家帮我看看哪里错了把,,谢了

Posted by xiaoqiangwj at 2008-10-25 05:50:16 on Problem 1753
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

typedef struct{
  int pre;
  int change;
}RECORD;

void PrintResult(int x,int root,RECORD record[]){
  int step=1;
  while (record[x].pre!=root){
   //cout <<"x="<<x<<"  pre"<<record[x].pre<<"  change"<<record[x].change<<endl;
    step++;
    x=record[x].pre;
  }
  //cout <<"x="<<x<<"  pre"<<record[x].pre<<"  change"<<record[x].change<<endl;

  if (step<3 || step>5) cout <<"Impossible"<<endl;
  else cout <<step<<endl;
}

void bfs(queue<int> Q, bool checked[],RECORD record[]){
  int s[16]={51200,58368,29184,12544,35968,20032,10016,4880,2248,1252,626,305,140,78,39,19};
  int root=Q.front();
  int x,i,newX;
  while(!Q.empty()){
    int x=Q.front();
    Q.pop();
    if(!checked[x]){
      //cout <<"x="<<x<<endl;
      for (i=0;i<=15;i++){
        newX=x^s[i];
        //cout <<"  "<<i<<"newx="<<newX<<endl;
        if (!checked[newX]){
          record[newX].pre=x;
          record[newX].change=i;
        }
        if (newX==0||(newX==65535)){
          PrintResult(newX,root,record);
          return;
        }
        else{
          Q.push(newX);
        }
      }
      checked[x]=true;
    }
  } 
}

int main(){
  queue<int> Q;
  bool checked[65537];
  RECORD record[65537];
  int i;
  unsigned int curr;
  char c;
  curr=0;
  for (i=0;i<65537;i++) checked[i]=false;
  for (i=15;i>=0;i--){
    cin >>c;
    if (c=='w') curr=curr|(1<<i);
    else curr=curr|(0<<i);
    //cout <<curr<<endl;
  }
  Q.push(curr);
  if (curr!=0 && (curr!=65535)) bfs(Q, checked,record);
  else cout <<"0"<<endl;
  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