HDU 4478 Where is King
题目大意:
一个王可以向周围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的更多相关文章
- hdu 5201 The Monkey King【容斥原理+组合数学】
原来我一开始以为的\( O(n^2) \)是调和级数\( O(nlog_2n) \)的! 首先枚举猴王的桃子个数\( x \),然后使用容斥原理,枚举有至少\( k \)个不满足的条件,那么这\( k ...
- HDU - 1512 Monkey King
Problem Description Once in a forest, there lived N aggressive monkeys. At the beginning, they each ...
- HDU 3861.The King’s Problem 强联通分量+最小路径覆盖
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 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). ...
- 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 ...
- HDU 5642 King's Order dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 King's Order Accepts: 381 Submissions: 1361 ...
- HDU 5644 King's Pilots 费用流
King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU 5642 King's Order 动态规划
King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...
随机推荐
- SSRS域账号下 User 'XXX' does not have required permissions的处理方法
SSRS安装完成后,点击Report Manager URL,提示:User 'XXX' does not have required permissions. Verify that suffici ...
- 用for循环实现的菱形图案
package com.wh.lingxing; import java.util.Scanner; public class LingXing { public static void main(S ...
- jmeter(九)分布式测试
Jmeter 是java 应用,对于CPU和内存的消耗比较大,因此,当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发用户就有些力不从心,甚至会引起JAVA内存溢出错误.为了让jmeter工具 ...
- 数据流和ByteArray
问题:如何把一个long类型的数写进一个文件里 所以现在有DataInputStream和DataOutputStream 这两个是节点流 例子代码: import java.io.*; public ...
- selenium通过autoit实现上传和下载
autoit安装目录如下: AutoIt Windows Info 用于帮助我们识Windows控件信息. Compile Script to.exe 用于将AutoIt生成 exe 执行文件. ...
- 快速体验openstack-用devstack安装openstack
官网安装说明: --2014年11月15日14:14:21 安装环境:Ubuntu12.04,安装官网的说明遇到了小问题,记录在这里 --http://docs.openstack.org/devel ...
- mysql 修改 root 密码
5.76中加了一些passwd的策略 MySQL's validate_password plugin is installed by default. This will require that ...
- vue-router: $router.push遇到的问题
如下图使用path时,跳转路由后的页面this.$route.params为undefined 改为name时,this.$route.params可以正确获取数据,如下图: 此为官方定义的固定搭配: ...
- QPushButton注册事件过滤器后按钮消失
版权声明:本文为博主原创文章,转载需要注明出处. RT,代码如下: ui.btn_set->installEventFilter(this); bool MousrHoverTest::even ...
- JavaScript——XMLHttpRequest 家族
https://www.zhangxinxu.com/wordpress/2013/10/understand-domstring-document-formdata-blob-file-arrayb ...