标题:帮忙看看,为什么没输出
取消只看楼主
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
已结贴  问题点数:20 回复次数:2 
帮忙看看,为什么没输出
#include<stdio.h>
#include<string.h>
int dir[8][2]={{2,1},{1,2},{-1,2},{-2,1},{1,-2},{2,-1},{-1,-2},{-2,-1}};
int count;
int n,m;
void bfs(int x,int y)
{
    int xx,yy;
    int i;
    for(i=0;i<8;i++)
    {
        xx=x+dir[i][0];
        yy=y+dir[i][1];
        if(xx>5||xx<=0||yy>4||yy<=0)
        continue;
        if(xx==n&&yy==m)
        {
            count++;
            continue;
        }
        bfs(xx,yy);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    count=0;
    bfs(n,m);
    printf("%d\n",count);
    return 0;
}
搜索更多相关主题的帖子: void continue include count 
2011-08-14 14:43
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
得分:0 
回复 2楼 TonyDeng
再帮忙看一下,这题目还要考虑什么?

马的走法

Time Limit:1000MS  Memory Limit:65536K
Total Submit:174 Accepted:104

Description

在一个4*5的棋盘上,输入马的起始位置坐标(纵、横),求马能返回初始位置的所有不同走法的总数(马走过的位置不能重复,马走“日”字)。

Input

多个测试数据。
每组2个数字

Output

输出不同走法的总数。

Sample Input


2 2
Sample Output


4596
Source


#include<stdio.h>
#include<string.h>
int dir[8][2]={{2,1},{1,2},{-1,2},{-2,1},{1,-2},{2,-1},{-1,-2},{-2,-1}};
int count;
int n,m;
int map[6][7];
void bfs(int x,int y)
{
    int xx,yy;
    int i;
    for(i=0;i<8;i++)
    {
        xx=x+dir[i][0];
        yy=y+dir[i][1];
        if(xx>5||xx<=0||yy>4||yy<=0)
        continue;
        if(map[xx][yy])
        continue;
        if(xx==n&&yy==m)
        {
            count++;
            continue;
        }
        map[xx][yy]=1;
        bfs(xx,yy);
        map[xx][yy]=0;
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {count=0;
    memset(map,0,sizeof(map));
    bfs(n,m);
    printf("%d\n",count);}
    return 0;
}
2011-08-14 15:00
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
得分:0 
明白了,谢谢大家了,原来是横坐标和纵坐标搞错了。谢谢了
2011-08-14 15:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-347587-1-1.html




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

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