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 ...
随机推荐
- Java基础知识之this关键字知识讲解
this关键字这里对java中this关键字的基础知识进行讲解,希望对热爱java的小伙伴有帮助!! /* this关键字代表了所属函数的调用者对象. this关键字的作用: 1. 如果存在同名成员变 ...
- Python跨域问题解决集合
Flask 安装插件 pip install flask-cors 使用 CORS函数配置全局路由 from flask_cors import * app = Flask(__name__) COR ...
- 【NX二次开发】Block UI 曲线收集器
属性说明 属性 类型 描述 常规 BlockID String 控件ID Enable Logical 是否可操作 Group ...
- sentinel (史上最全+入门教程)
文章很长,建议收藏起来,慢慢读! 高并发 发烧友社群:疯狂创客圈 为小伙伴奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : 极致经典 < Java 高并发 三部曲 > 面试必备 + 大厂 ...
- 使用axios模拟表单提交
1.需求背景 最近在实验室写一个Spring前后端分离的项目,项目中使用Spring Security组件实现系统的认证和授权,当Security的认证模式设置为FormLogin时(如下代码),前端 ...
- cos中的文件结构(DF/EF/MF/FID/AID/SFI..)
转载自:https://blog.csdn.net/Enjoy_endless/article/details/75108349 刚开始接触CPU卡的时候,对于各种文件.应用的定义容易模糊不清,通常不 ...
- Unity 不能添加脚本组件,脚本类可能丢失
报错: 把脚本拖到游戏对象,显示如下 原因: 你可能修改了脚本名称,但此时Unity没有找到那个对应脚本名称的类
- Java并发之Semaphore源码解析(二)
在上一章,我们学习了信号量(Semaphore)是如何请求许可证的,下面我们来看看要如何归还许可证. 可以看到当我们要归还许可证时,不论是调用release()或是release(int permit ...
- Pytest学习笔记10-生成html报告
前言 在pytest中,如何生成html测试报告呢,pytest提供了pytest-html插件,可以帮助我们生成测试报告,当然,如果希望生成更加精美的测试报告,我们还可以使用allure生成报告,下 ...
- MySQL数据库性能优化与监控实战(阶段四)
MySQL数据库性能优化与监控实战(阶段四) 作者 刘畅 时间 2020-10-20 目录 1 sys数据库 1 2 系统变量 1 3 性能优化 1 3.1 硬件层 1 3.2 系统层 1 3.3 软 ...