【搜索】URAL 1498 Stroke at Full Speed

点击打开链接

题意:

一个骑士能走K步,要走到恶魔的相邻格子才能打到恶魔。

要求走到恶魔相邻的格子时走的直线距离最长。



比如C是恶魔旁边的格子

骑士从A点出发按照这个路径的伤害是len(BC)

思路:先预处理 骑士出发到其他点所需要的步数

枚举恶魔相邻的点的水平/竖直上的点。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <deque>
#include <map>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
typedef long long  LL;
const int MAXN = 120000;
const int MAXM = 140000;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int t[122][122],x2,y2,n,m;
int s,e;
struct node
{
    int x,y,step;
};
int dd[4][2]= {0,1,0,-1,1,0,-1,0};
int inmap(int x,int y)
{
    if(x<1||x>n||y<1||y>m||(x==x2&&y==y2))
        return true;
    return false;
}
int bfs(int x,int y)
{
    queue<node>q;
    node front ,rear ;
    front.x=x,front.y=y,front.step=0;
    t[x][y]=0;
    q.push(front);
    while(!q.empty())
    {
        front=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            rear.x=front.x+dd[i][0];
            rear.y=front.y+dd[i][1];
            if(t[rear.x][rear.y]!=INF||inmap(rear.x,rear.y)) continue;
            rear.step=t[rear.x][rear.y]=front.step+1;
            q.push(rear);
        }
    }
}
int main()
{
    int k,maxx=0;
    cler(t,INF);
    cin>>n>>m>>k;
    cin>>s>>e>>x2>>y2;
    bfs(s,e);
//    for(int i=1;i<=n;i++)
//    {
//        for(int j=1;j<=m;j++)
//            printf("%d ",t[i][j]);
//        puts("");
//    }
    for(int i=0; i<4; i++)
    {
        int x3=x2+dd[i][0],y3=y2+dd[i][1];
        if(x3<1||x3>n||y3<1||y3>m) continue;
        int l1,l2,l3,l4;
        if(i==0) l1=1,l2=n,l3=y2+1,l4=m;
        if(i==1) l1=1,l2=n,l3=1,l4=m-1;
        if(i==2) l1=x2+1,l2=n,l3=1,l4=m;
        if(i==3) l1=1,l2=x2-1,l3=1,l4=m;
        for(int i=l1; i<=l2; i++)//n
        {
            int c=(int)abs(i-x3);
            if(k-t[i][y3]>=c)
                maxx=max(maxx,c+1);
        }
        for(int i=l3; i<=l4; i++)//m
        {
            int c=(int)abs(i-y3);
            if(k-t[x3][i]>=c)
                maxx=max(maxx,c+1);
        }
    }
    cout<<maxx<<endl;
    return 0;
}
/*

6 1 8
6 1
5 1
ans:1
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值