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 linusc at 2010-05-02 18:06:50 on Problem 1077
中转用,不要动,也请不要评论:
/*
 * POJ 1077 EIGHT
 * Author:wzy[linusc]
 * Last Edit 9:32pm,30 April,2010
 * */
#include <iostream>
#include <map>
#define MAX_Q_SIZE 800000
#define FR 0
#define BK 1
using namespace std;
const int Ex_Addr[4][9]={{1,2,2,4,5,5,7,8,8},//R
                         {0,0,1,3,3,4,6,6,7},//L
                         {3,4,5,6,7,8,6,7,8},//D
                         {0,1,2,0,1,2,3,4,5}}; //U
        S_Buff[2]={1,-1};
typedef char puz[9];//Attention that it could not be read by "%s",or "cin >>x"
typedef int MNode[2];//0-Pre;1-Data
puz St,Gl={'1','2','3','4','5','6','7','8','0'};
map<MNode,int> HashMap;
class TQ
{
public:
    TQ()
    {
        f=r=0;
    }
    clear()
    {
        f=r=0;
    }
    EQ(int Xd,int Xs)
    {
        DT[r][0]=Xd;
        DT[r][1]=Xs;
        r=(r+1)%MAX_Q_SIZE;
    }
    DQ(int &Xd,int &Xs)
    {
        Xd=DT[f][0];
        Xs=DT[f][1];
        f=(f+1)%MAX_Q_SIZE;
    }
    int f,r;
private:
    int DT[MAX_Q_SIZE][2]; //0-data[hashed];1-step
}Q[2];
#define PUS(S,Xd,Xs) ({Q[S].EQ(Xd,Xs);HashMap[Xd]=Xs*S_Buff[S];})
#define EMP(S) (Q[S].f==Q[S].r)
int BD_BFS();
int main()
{
    char Decod;
    for (int i=0;i<=8;++i)
    {
        cin >>St[i];
        cin >>Decod;
        if (St[i]=='x') St[i]='0';
    }
    cout <<BD_BFS()<<endl;
}
inline int EnCode(const puz &x)
{
    int ans=x[0]-'0';
    for (int i=1;i<=8;++i)
    {
        ans*=10;
        ans+=x[i]-'0';
    }
    return ans;
}/*C*/
inline void DeCode(int Cd,puz& Xe)
{
    int Ti=Cd,Ir;
    for (Ir=8;Ir>=0;--Ir)
    {
        Xe[Ir]=Ti%10+'0';
        Ti=Ti/10;
    }
}/*C*/
int expand(int sign)
{
    #define SWAP(A,B) ({T=Tm[A];Tm[A]=Tm[B];Tm[B]=T;})
    int Dr,Se,XLoc;char T;puz Dt,Tm;
    Q[sign].DQ(Dr,Se);
    DeCode(Dr,Dt);
    for (XLoc=0;XLoc<=8;++XLoc) if (Dt[XLoc]=='0') break;
    for (int dir=0;dir<=3;++dir)
    {
        Tm=Dt;SWAP(Tm[Ex_Addr[dir][XLoc]],XLoc);
        HashMap.find(
    }
}
int BD_BFS()
{
    int fr=EnCode(St),bk=EnCode(Gl);
    //[Init]
    HashMap.clear();
    PUS(FR,fr);
    PUS(BK,bk);
    //[/Init]
    do
    {
        if (!EMP(FR)) expa
    }
    while (!EMP(BK) || !(EMP(FR)));
}



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