正文

走马2007-09-06 09:52:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lingdlz/29158.html

分享到:

Playing Chess
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 18, Accepted users: 18
Problem 10763 : No special judgement
Problem description
yiyi and birdman like to play chess.They sometimes play chess in QQ game. They discovered that the game cost a lot of time. They have lots of things to do, for instance doing homework, programming.So they come up with a good game, this game is played on the chessboard too, Is a 4 × 3 Lattice. However, only a pawn - horse. The horse on the chessboard of arbitrary position ,The pawn returns to the original location of a number of different routes ,(if a position has been arrived then should not go again and the horse takes ‘日’ route), They have to give a total number of different routes and the faster is the winner. Because they are very good at programming , Through programming they can easily give the answer. This new game is not a challenge to them ,But it maybe a challenge to you. Your task now is to work out a procedure to tell us the answer ,can you win one of them?


Input
The input consists of some test cases. Each input a lines. Each line consists of two integer, StarX <= 3 and StarY <= 4 (the original position of the horse on the chessboard).End of EOF.


Output
For each input set, output integer N,the total number of different routes the horse can return to the original position .If the position is not satisfied with the above conditions of the intput ,output “Error !”


Sample Input
0 -1
0 0
0 1
Sample Output
Error !
1508
3457
Judge Tips

The routes of picture (1) is right, but (2) is wrong, because (2,1) arrived tiwice .


Problem Source

/// 用递归就是了,//// 水题充数

#include <iostream>
using namespace std;
int sum,starx,stary;
bool chess[5][4];

void get(int x, int y);
void deal(int x, int y){
    if(x==starx && y==stary)
        sum++;
    else if(!chess[y][x]){
        chess[y][x] = true;
        get(x,y);
        chess[y][x] = false;
    }
}

void get(int x, int y){
    if(x+2<=3){
        if(y+1<=4)
            deal(x+2,y+1);
        if(y-1>=0)
            deal(x+2,y-1);
    }
    if(x-2>=0){
        if(y+1<=4)
            deal(x-2,y+1);
        if(y-1>=0)
            deal(x-2,y-1);
    }
    if(y+2<=4){
        if(x+1<=3)
            deal(x+1,y+2);
        if(x-1>=0)
            deal(x-1,y+2);
    }
    if(y-2>=0){
        if(x+1<=3)
            deal(x+1,y-2);
        if(x-1>=0)
            deal(x-1,y-2);
    }
}

int main(){
    for(; cin>>starx>>stary; ){
        if(starx<0 || starx>3 || stary<0 || stary>4)
            cout<<"Error !"<<endl;
        else{
            sum = 0;
            get(starx,stary);
            cout<<sum<<endl;
        }
    }
    return 0;
}

阅读(2866) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册