搜索
查看: 1021|回复: 10
打印 上一主题 下一主题

宝岛探险12035是不是出错了?

[复制链接]
跳转到指定楼层
楼主
发表于 2016-2-12 17:30:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
宝岛探险12035是不是有错误的 一直在评判 我后来直接输出都不行=-=求解 0人做对  
沙发
发表于 2016-8-27 14:40:31 | 只看该作者
板凳
发表于 2016-8-27 15:26:40 | 只看该作者
地板
发表于 2016-8-27 15:27:31 | 只看该作者
没办法
5#
发表于 2016-9-6 17:43:57 | 只看该作者
6#
发表于 2016-9-27 22:59:08 | 只看该作者
是的,没有测试数据
7#
发表于 2016-10-1 20:55:31 | 只看该作者
也许是你做错了
8#
发表于 2016-10-1 21:55:40 | 只看该作者
哈哈哈急急急急急急急急急急急急急急急急急急就
9#
发表于 2016-11-16 19:53:13 | 只看该作者
不晓得呢,你看看代码,似乎是没有测试数据
10#
发表于 2016-11-17 21:55:11 | 只看该作者
呃,那个,算法书上好像有答案,但不是满分,要改一下。
11#
发表于 2016-11-19 20:22:55 | 只看该作者
本帖最后由 黑豆 于 2016-11-19 20:44 编辑

可参考我刚写的代码:[mw_shl_code=applescript,true]#include <stdio.h>
#include <stdlib.h>

#define MAX 101
//Map
int data[MAX][MAX] = {0};
//whether be searched
int flag[MAX][MAX] = {0};
int n = 0,m =0;

int moveX[4] = {0, 0, -1, 1};
int moveY[4] = {-1, 1, 0, 0};

int result = 0;

void DFS(int x, int y) {
    int i;
    int tempx,tempy;

    for (i = 0; i < 4; i++){
        tempx = x + moveX;
        tempy = y + moveY;
        if (flag[tempy][tempx] != 1 && data[tempy][tempx] > 0) {//not mark and it is land
            result++;
            flag[tempy][tempx] = 1;
            DFS(tempx, tempy);
        }
    }

}
int main()
{
    int i,j,x,y;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w",stdout);
    scanf("%d%d%d%d", &n,&m,&x,&y);

    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++){
            scanf("%d", &data[j]);
        }
    //(6,8),8应该是上往下算第8行
    DFS(y,x);
    printf("%d", result);

    return 0;
}
[/mw_shl_code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表