[USACO3.3]亚瑟王的宫殿 Camelot 有点bug,求大神。调试3天了┭┮﹏┭┮
											https://www.

> Run 13: Execution error: Your program did not produce an answer
that was judged as correct. The program stopped at 0.028 seconds;
it used 7132 KB of memory. At character number 2, your answer says
'0' while the correct answer says '1'.
Here are the respective outputs:
----- our output ---------
11
---- your output ---------
10
--------------------------
------ Data for Run 13 [length=24 bytes] ------
8 8
D 5
A 3 A 8 H 1 H 8
----------------------------
 程序代码:
程序代码:/*
ID:luojiny1
LANG:C++
TASK:camelot
*/
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#define INF 0x3f3f3f3f
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
const int maxR=31,maxC=28;
int R,C,n=0;
int kx,ky,nx[maxR*maxC],ny[maxR*maxC],d[maxC][maxR][maxC][maxR],ans=INF;
struct point{
    int x,y,step;
};
void bfs(int sx,int sy){
    int dx[8]={-1,1,2,2,1,-1,-2,-2};
    int dy[8]={2,2,1,-1,-2,-2,-1,1};
    bool vis[maxC][maxR]={0};
    queue<point>Q;
    Q.push((point){sx,sy,0});
    while(!Q.empty()){
        point a=Q.front();Q.pop();
        int x=a.x,y=a.y;
        if(vis[x][y])continue;
        vis[x][y]=1;
        d[sx][sy][x][y]=a.step;
        for(int i=0;i<8;i++){
            int newx=x+dx[i],newy=y+dy[i];
            if(newx>=0&&newx<C&&newy>=0&&newy<R)Q.push((point){newx,newy,a.step+1});
        }
    }
    
}
int main()
{
//    freopen("camelot.in","r",stdin);
//    freopen("camelot.out","w",stdout);
    memset(d,0x3f3f3f3f,sizeof(d));
    char ch;
    scanf("%d %d\n",&R,&C);
    scanf("%c %d\n",&ch,&ky);
    kx=ch-'A',ky--;
    while((ch=getchar())!=EOF)if(ch>='A'&&ch<='Z'){
        scanf("%d",&ny[n]);
        ny[n]--,nx[n++]=ch-'A';
        bfs(nx[n-1],ny[n-1]);
    }
    if(n==0){
        printf("0\n");
        return 0;
    }
    for(int dx=-1;dx<=1;dx++)
    for(int dy=-1;dy<=1;dy++){
        int newn=dx+kx,newm=dy+ky;
        if(newn>=0&&newn<C&&newm>=0&&newm<R)bfs(newn,newm);} 
        
    for(int newx=0;newx<C;newx++)
    for(int newy=0;newy<R;newy++)
    {
        int t=0;
        for(int i=0;i<n;i++)
            t+=d[nx[i]][ny[i]][newx][newy];
        for(int dx=-1;dx<=1;dx++)
        for(int dy=-1;dy<=1;dy++){
            int newn=dx+kx,newm=dy+ky;
            if(newn>=0&&newn<C&&newm>=0&&newm<R)
            for(int i=0;i<n;i++)    
            ans=min(ans,t-d[nx[i]][ny[i]][newx][newy]+d[nx[i]][ny[i]][newn][newm]+abs(kx-newn)+abs(ky-newm)+min(d[newn][newm][newx][newy],abs(newn-newx)+abs(newm-newy)));
        }
    }
    printf("%d\n",ans);
    return 0;
}[此贴子已经被作者于2017-8-9 12:54编辑过]



 
											





 
	    

 
	





 ~~~
~~~										
					
	