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 |
为什么我的代码在本地运行良好,在你们那边却re? 你们的deque是不是和vc6一样的?为什么我的代码在本地运行良好,在你们那边却re? #include <stdio.h> #include <deque> using namespace std; const int Infinite=0xffffff; const int Size=25; int N,M,L; int Area[Size][Size]; int Short[Size][Size]; struct Point { int n; int m; }; int MoveN[4]={-1,0,1,0}; int MoveM[4]={0,-1,0,1}; int StoneAmount; int Result; deque<Point> Snake; deque<Point>::iterator it; void Debug() { int i,j; for(i=0;i<=N+1;i++) { for(j=0;j<=M+1;j++) { printf("%d",Area[i][j]); } printf("\n"); } } int Read() { int i,j,k; Point p; scanf("%d %d %d",&N,&M,&L); if(N==0 && M==0 && L==0) return -1; Snake.clear(); for(i=0;i<L;i++) { scanf("%d %d",&p.n,&p.m); Snake.push_back(p); } j=N+1; k=M+1; for(i=0;i<=k;i++) { Area[0][i]=1; Area[j][i]=1; } for(i=0;i<=j;i++) { Area[i][0]=1; Area[i][k]=1; } for(i=1;i<=N;i++) { for(j=1;j<=M;j++) { Area[i][j]=0; } } scanf("%d",&StoneAmount); for(i=0;i<StoneAmount;i++) { scanf("%d %d",&p.n,&p.m); Area[p.n][p.m]=1; } return 0; } void MakeShort() { int i,j; Point p,now; deque<Point> de; p.n=1; p.m=1; de.push_back(p); for(i=1;i<=N;i++) { for(j=1;j<=M;j++) { Short[i][j]=Infinite; } } Short[1][1]=0; while(!de.empty()) { p=de.front(); de.pop_front(); for(i=0;i<4;i++) { now.n=p.n+MoveN[i]; now.m=p.m+MoveM[i]; if(Area[now.n][now.m]==0 && Short[now.n][now.m]==Infinite) { Short[now.n][now.m]=Short[p.n][p.m]+1; de.push_back(now); } } } } void Do(int step) { // Debug(); int i; Point head,tail,go; head=Snake.front(); if(step + Short[head.n][head.m] >= Result) return ; if(head.n==1 && head.m==1) { Result=step; return ; } tail=Snake.back(); Snake.pop_back(); for(i=0;i<4;i++) { go.n=head.n+MoveN[i]; go.m=head.m+MoveM[i]; if(Area[go.n][go.m]==0) { Area[tail.n][tail.m]=0; Area[go.n][go.m]=1; Snake.push_front(go); Do(step+1); Snake.pop_front(); Area[go.n][go.m]=0; Area[tail.n][tail.m]=1; } } Snake.push_back(tail); } void Work() { Point p; Result=Infinite; MakeShort(); for(it=Snake.begin();it!=Snake.end();it++) { p=*it; Area[p.n][p.m]=1; } Do(0); if(Result==Infinite) Result=-1; } int main() { // freopen("in.txt","r",stdin); int i=1; while(Read()!=-1) { Work(); printf("Case %d: %d\n",i,Result); i++; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator