Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数组太大#include<stdio.h> #include<math.h> #include<string.h> #define n6 1000000 #define n7 10000000 #define n5 100000 int D,U; int U0,U1; int p0; int st,en,p,q; int map[n7][3]; bool used[n7]; int swap0() { //////// p0=D/n6; U=D%n6; U0=U/n6; U1=U%(int)pow(10,7-p0)/(int)pow(10,6-p0);// 光标 D=D+(U1-U0)*n5+(U0-U1)*(int)pow(10,6-p0); return D; } int swap1() { U0=U%10; ///////p0=D/n6; U1=U%(int)pow(10,7-p0)/(int)pow(10,6-p0); D=D+(U1-U0)+(U0-U1)*(int)pow(10,6-p0); return D; } int up() { p0=D/n6; D+=(int)pow(10,6-p0); return D; } int down() { D-=(int)pow(10,6-p0); return D; } int left() { D-=n6; return D; } int right() { D+=n6; return D; } int insert() { if(used[D]==0) { used[D]=1; q++; map[q][1]=D; map[q][2]=map[p][2]+1; } return D; } int main() { scanf("%d%d",&st,&en); p=1; q=1; map[1][1]=st+n6; map[1][2]=0; memset(used,sizeof(used),0); used[st+n6]=1; do { if(map[p][1]%n6==en) { printf("%d\n",map[p][2]); break; } D=map[p][1]; p0=D/n6; if(p0!=1) { swap0(); insert(); } if(p0!=6) { swap1(); insert(); } if(p0!=1) { left(); insert(); } if(p0!=9) { right(); insert(); } U=D%n6; U1=U%(int)pow(10,7-p0)/(int)pow(10,6-p0);// 光标 if(U1!=9) { up(); insert(); } if(U1!=0) { down(); insert(); } p++; }while(p!=q); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator