POJ2044 Weather Forecast 题解
写了一个小时……不会……无耻地看题解去了……
关键在于存储状态的方式,真没想到……
每个状态要存当前坐标、天数和这个状态下四个角的情况,vis数组存整张图的访问情况,有天数、坐标、四个角的情况,只有这样才能保证唯一性。
还没见过这么毒瘤的状态记录题,我还是太 naive 了……
代码要多学习一个
#include <bits/stdc++.h>
using namespace std;
const int dx[9]={0,-1,-2,1,2,0,0,0,0};
const int dy[9]={0,0,0,0,0,-1,-2,1,2};
struct Node{int day,x,y,s[4];};
int n;
bool a[366][4][4],vis[366][4][4][7][7][7][7];
inline bool check(int x,int y,int day,int d[])
{
if(x<0||y<0||x>2||y>2) return 0;
for(int i=0;i<=1;++i)
for(int j=0;j<=1;++j)
if(a[day][x+i][y+j]) return 0;
if(d[0]>=7||d[1]>=7||d[2]>=7||d[3]>=7) return 0;
return 1;
}
bool bfs()
{
if(a[1][1][1]||a[1][1][2]||a[1][2][1]||a[1][2][2]) return 0;
queue<Node> q; memset(vis,0,sizeof(vis));
int sd[4];
q.push((Node){1,1,1,{1,1,1,1}});
vis[1][1][1][1][1][1][1]=1;
while(!q.empty())
{
Node now=q.front(); q.pop();
if(now.day==n) return 1;
for(int i=0;i<9;++i)
{
int x=now.x+dx[i],y=now.y+dy[i];
for(int j=0;j<4;++j) sd[j]=now.s[j]+1;
if(x==0&&y==0) sd[0]=0;
if(x==0&&y==2) sd[1]=0;
if(x==2&&y==0) sd[2]=0;
if(x==2&&y==2) sd[3]=0;
if(check(x,y,now.day+1,sd)&&\
!vis[now.day+1][x][y][sd[0]][sd[1]][sd[2]][sd[3]])
{
q.push((Node){now.day+1,x,y,{sd[0],sd[1],sd[2],sd[3]}});
vis[now.day+1][x][y][sd[0]][sd[1]][sd[2]][sd[3]]=1;
}
}
}
return 0;
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=1;i<=n;++i)
for(int j=0;j<4;++j)
for(int k=0;k<4;++k)
scanf("%d",&a[i][j][k]);
printf("%d\n",bfs());
}
return 0;
}
POJ2044 Weather Forecast 题解的更多相关文章
- POJ 2044 Weather Forecast
意甲冠军:有一2*2云,而一个4*4范围.在当天密布区必须有雨.有云4招式种类 .期间希望不要下雨,并且一个地方不能有连续7天没下雨. 思路:首先解决一个地方不能有连续7天没下雨的情况,要让地图上的全 ...
- 【POJ 2044】 Weather Forecast
[题目链接] http://poj.org/problem?id=2044 [算法] 广度优先搜索 [代码] #include <algorithm> #include <bitse ...
- CoderForces Round60-(1117A,1117B,1117C题解)
A. Best Subsegment time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- weather API 天气api接口 收集整理
腾讯 http://sou.qq.com/online/get_weather.php?callback=Weather&city=南京 中国天气-weather.com.cn http:// ...
- English trip V1 - B 5.Is It Cold Outside? 外面很冷? Teacher:Corrine Key: weather
In this lesson you will learn to talk about the weather. 本节课将学习到关于天气 课上内容(Lesson) 词汇(Key Word ) # 关于 ...
- Codeforces Gym 100531J Joy of Flight 变换坐标系
Joy of Flight 题目连接: http://codeforces.com/gym/100531/attachments Description Jacob likes to play wit ...
- Codeforces Round #327 (Div. 1) B. Chip 'n Dale Rescue Rangers 二分
题目链接: 题目 B. Chip 'n Dale Rescue Rangers time limit per test:1 second memory limit per test:256 megab ...
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理
D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- UVA1623-Enter The Dragon(并查集)
Problem UVA1623-Enter The Dragon Accept: 108 Submit: 689Time Limit: 3000 mSec Problem Description T ...
随机推荐
- Django(58)viewsets视图集详解
前言 ViewSet 只是一种基于类的视图,它不提供任何方法处理程序(如 .get()或.post()),而是提供诸如.list()和 .create() 之类的操作. ViewSet 的方法处理程序 ...
- 谷歌chrome浏览器network中Stalled分析和优化
谷歌chrome浏览器network中Stalled分析和优化 问题由来 最近项目上要求首页的加载速度,查看浏览器的network发现接口加载速度非常慢. 问题解决思路 SSL 网上有人因为图片加载, ...
- UF_DRF 制图符号标注尺寸
Open C uc5530uc5531uc5532uc5533uc5534uc5540uc5541uc5542uc5543uc5550uc5551uc5563uc5566uf5505uf5506uf5 ...
- Django基础之模板层
内容概要 模板层(模板语法) 模板语法传值模板语法过滤器(内置方法)模板语法标签(流程控制)自定义过滤器和标签(了解) 模板的导入与继承(面向对象) 内容详细 1 模板层之模板语法传值 http ...
- Python编解码问题与文本文件处理
编解码器 在字符与字节之间的转换过程称为编解码,Python自带了超过100种编解码器,比如: ascii(英文体系) gb2312(中文体系) utf-8(全球通用) latin1 utf-16 编 ...
- 题解 P2257 YY的GCD
P2257 YY的GCD 解题思路 果然数论的题是真心不好搞. 第一个莫比乌斯反演的题,好好推一下式子吧..(借鉴了blog) 我们要求的答案就是\(Ans=\sum\limits_{i=1}^{n} ...
- Gogs+Jenkins+Docker 自动化部署.NetCore
环境说明 腾讯云轻量服务器, 配置 1c 2g 6mb ,系统是 ubuntu 20.14,Docker 和 Jenkins 都在这台服务器上面, 群晖218+一台,Gogs 在这台服务器上. Doc ...
- win7旗舰版任务栏窗口不合并显示,鼠标移至窗口时可预览应用内容
1.鼠标移至任务栏--右键--属性: 2.选择"当任务栏被占满时合并"或"从不合并",第一个选项更优: 3.右键桌面"计算机"的" ...
- js jq计算器
<html><head><meta http-equiv="Content-type" content="text/html; charse ...
- ES服务的搭建(八)
看下图的淘宝页面,可以看到搜索有多个条件及搜索产品,并且支持多种排序方式,例如按价格:其实这块有个特点,就是不管你搜索哪个商品他都是有分类的,以及他对应的品牌,这两个是固定的,但其它参数不一定所有商品 ...