题目大意:

一个王可以向周围8个方格走,如果都不通留在原地,t秒后,他可能存在的位置数

这题数据量过大,我们需要通过奇偶性判断,如果t = 0可以到达,说明 t=2,4,6.。。。都可以到达

所以我这用dp[N][N][2] 来记录x,y位置上奇数和偶数时间分别到达那点的最短时间,如果不存在,用-1表示

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int N = ;
int dp[N][N][],n,t,x,y,vis[N][N];
char mat[N][N];
int dir[][] = {{,},{-,},{,},{,-},{,-},{,},{-,},{-,-}}; struct Node{
int x,y;
Node(int x,int y):x(x),y(y){}
}; queue<Node> q; void bfs()
{
q.push(Node(x,y));
vis[x][y] = ;
while(!q.empty()){
Node t = q.front();
q.pop();
vis[t.x][t.y]=; for(int i=;i<;i++){
int xx = t.x + dir[i][];
int yy = t.y + dir[i][];
if(xx>=&&xx<=n&&yy>=&&yy<=n&&mat[xx][yy] == '.'){
int flag = ;
if((dp[xx][yy][] < || dp[xx][yy][] > dp[t.x][t.y][] + ) && dp[t.x][t.y][] >= )
{
dp[xx][yy][] = dp[t.x][t.y][] + ;
flag = ;
}
if((dp[xx][yy][] < || dp[xx][yy][] > dp[t.x][t.y][] + ) && dp[t.x][t.y][] >= )
{
dp[xx][yy][] = dp[t.x][t.y][] + ;
flag = ;
} if(flag && !vis[xx][yy])
{
vis[xx][yy]=;
q.push(Node(xx,yy));
}
}
}
}
}
int main()
{
//freopen("test.in","rb",stdin);
//cout << "Hello world!" << endl;
int C;
scanf("%d",&C);
while(C--){
scanf("%d%d%d%d",&n,&t,&x,&y);
for(int i=;i<=n;i++)
scanf("%s",mat[i]+); memset(vis,,sizeof(vis));
memset(dp,-,sizeof(dp));
dp[x][y][]=; bfs(); int tmp = t&;
int ans = ;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dp[i][j][tmp]!=- && dp[i][j][tmp]<=t)
ans++;
}
}
printf("%d\n",max(ans,));
}
return ;
}

HDU 4478 Where is King的更多相关文章

  1. hdu 5201 The Monkey King【容斥原理+组合数学】

    原来我一开始以为的\( O(n^2) \)是调和级数\( O(nlog_2n) \)的! 首先枚举猴王的桃子个数\( x \),然后使用容斥原理,枚举有至少\( k \)个不满足的条件,那么这\( k ...

  2. HDU - 1512  Monkey King

    Problem Description Once in a forest, there lived N aggressive monkeys. At the beginning, they each ...

  3. HDU 3861.The King’s Problem 强联通分量+最小路径覆盖

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. HDU 4489 The King's Ups and Downs

    HDU 4489 The King's Ups and Downs 思路: 状态:dp[i]表示i个数的方案数. 转移方程:dp[n]=∑dp[j-1]/2*dp[n-j]/2*C(n-1,j-1). ...

  5. HDU 4489 The King’s Ups and Downs dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4489 The King's Ups and Downs Time Limit: 2000/1000 ...

  6. HDU 5642 King's Order dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 King's Order  Accepts: 381  Submissions: 1361   ...

  7. HDU 5644 King's Pilots 费用流

    King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...

  8. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  9. HDU 5642 King's Order 动态规划

    King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...

随机推荐

  1. 区间DP UVA 10453 Make Palindrome

    题目传送门 /* 题意:问最少插入多少个字符使得字符串变成回文串 区间DP:dp[i][j]表示[l, r]的字符串要成为回文需要插入几个字符串,那么dp[l][r] = dp[l+1][r-1]; ...

  2. QQ文件没有读取权限,60017导致QQ无法登陆的终极解决办法

    每隔一段时间,我的QQ就无法登陆,提示:QQ文件没有读取权限,60017导致QQ无法登陆的终极解决办法 点击了解详情发现里面的解决办法根本不起作用,网上 说的各种解决办法都不起作用,解决办法如下 1. ...

  3. InputStream和OutputStream的一遍博客 分析非常到位

    http://www.cnblogs.com/springcsc/archive/2009/12/03/1616187.html

  4. 172 Factorial Trailing Zeroes 阶乘后的零

    给定一个整数 n,返回 n! 结果尾数中零的数量.注意: 你的解决方案应为对数时间复杂度. 详见:https://leetcode.com/problems/factorial-trailing-ze ...

  5. Codeforces Beta Round #98 (Div. 2)(A-E)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  6. [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)

    本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/sorting-fi ...

  7. ES之事件绑定,解除绑定以及事件冒泡、事件捕获

    绑定事件的处理方法任何元素都有事件属性,而绑定事件就是将这个事件与一个函数相连接. ①句柄事件dom.onXXX = function () {代码块} 以on开头的事件属于句柄事件兼容性非常好,但是 ...

  8. Sqlmap脱库之“你的数据我所见”

    废话不多说,介绍和理论啥的网上一搜一大把,一次只为tuoku. 实战操作: 1.在网上找个index.php?id=1的站点 2.很明显看到了脱下裤子的希望,sqlmap走一把.查看数据库 3.怎么看 ...

  9. select在数据库中有两种含义

    select在数据库中有两种意思 (1)是赋值的意思(2)是输出,打印的意思我想你问的大概是赋值吧print和 select在数据库中都有打印输出的意思 用法是:select @aa=select* ...

  10. PPTP的搭建

    一.准备 1.检查是否支持pptp modprobe ppp-compress-18 && echo yes yes支持 2.是否开启tun cat /dev/net/tun 返回ca ...