哈理工 1943

来源:互联网 发布:电脑跳舞毯软件 编辑:程序博客网 时间:2024/04/30 05:21

马是走“日”的
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 151(86 users) Total Accepted: 90(81 users) Rating: Special Judge: No
Description
xuxu闲来无事,去买了盘象棋,准备参加下届哈理工象棋大赛,(xuxu有一个特异功能,他能够定住对手若干秒,以便他能吃掉对方的棋子,然后若无其事的继续下棋)这天它和biaobiao在练习,xuxu大喊一声“阿门”,就定住了biaobiao,开始快速移动他的棋子,他还有一个习惯就是喜欢在特异功能的时间内使用马去吃掉对方棋子。。。假设每走完一步都需要一秒,现在你能帮他计算出他最少需要多少秒能够吃掉biaobiao的棋子么??(棋盘为9*9的方格棋盘,是不是很奇怪。。。但是马走的规则和中国象棋一样,是走“日”的)。

Input

本题有多组测试数据。

每行有四个数x1,y1,x2,y2。x1,y1表示xuxu的马所在的行和列,x2,y2表示他想要吃掉对方棋子所在的行和列。(1 <= x1,y1,x2,y2 <= 9, x1 != x2 && y1!=y2)。

Output
输出”I can eat it within n s.”, n表示吃掉对方棋子所需要的最小时间。

Sample Output
6 9 8 1
4 6 6 9
Hint
I can eat it within 4 s.
I can eat it within 3 s.
Source
新生练习赛(2013.11.17)
Author
cyh@hrbust

#include<stdio.h>#include<map>#include<queue>#include<iostream>#include<string>#include<string.h>using namespace std;int maps[103][103],vis[13][13];struct nana{    int x,y;} p[1003];int dx[8]= {1,2,1,2,-1,-2,-1,-2};int dy[8]= {2,1,-2,-1,2,1,-2,-1};int temp[100][100]={0};void dfs(nana a){    temp[a.x][a.y]=0;    queue<nana>q;    memset(vis,0,sizeof(vis));    nana first,next,second;    first=a;    vis[first.x][first.y]=1;    q.push(first);    while(!q.empty())    {        next=q.front();        q.pop();        for(int i=0; i<8; i++)        {            second=next;            second.x+=dx[i];            second.y+=dy[i];            if(vis[second.x][second.y]==0&&second.x>0&&second.y<=9&&second.y>0&&second.x<=9)            {                temp[second.x][second.y]=temp[next.x][next.y]+1;                q.push(second);                vis[second.x][second.y]=1;            }        }    }}int main(){    nana a;    int x,y;    while(~scanf("%d%d%d%d",&a.x,&a.y,&x,&y))    {        temp[100][100]={0};        dfs(a);        printf("I can eat it within %d s.\n",temp[x][y]);    }}
0 0
原创粉丝点击