| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2089 人关注过本帖
标题:[USACO3.3]亚瑟王的宫殿 Camelot 有点bug,求大神。调试3天了┭┮﹏┭┮
取消只看楼主 加入收藏
罗进瑶
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-8-9
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
[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编辑过]

搜索更多相关主题的帖子: for include int point abs 
2017-08-09 12:53
罗进瑶
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-8-9
收藏
得分:0 
@xzlxzlxzl
@renkejun1942
@ehszt
@jklqwe111
2017-08-09 12:55
快速回复:[USACO3.3]亚瑟王的宫殿 Camelot 有点bug,求大神。调试3天了┭┮﹏┭ ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053649 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved