写了一个小时……不会……无耻地看题解去了……


关键在于存储状态的方式,真没想到……

每个状态要存当前坐标、天数和这个状态下四个角的情况,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 题解的更多相关文章

  1. POJ 2044 Weather Forecast

    意甲冠军:有一2*2云,而一个4*4范围.在当天密布区必须有雨.有云4招式种类 .期间希望不要下雨,并且一个地方不能有连续7天没下雨. 思路:首先解决一个地方不能有连续7天没下雨的情况,要让地图上的全 ...

  2. 【POJ 2044】 Weather Forecast

    [题目链接] http://poj.org/problem?id=2044 [算法] 广度优先搜索 [代码] #include <algorithm> #include <bitse ...

  3. CoderForces Round60-(1117A,1117B,1117C题解)

    A. Best Subsegment time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. weather API 天气api接口 收集整理

    腾讯 http://sou.qq.com/online/get_weather.php?callback=Weather&city=南京 中国天气-weather.com.cn http:// ...

  5. 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 ) # 关于 ...

  6. Codeforces Gym 100531J Joy of Flight 变换坐标系

    Joy of Flight 题目连接: http://codeforces.com/gym/100531/attachments Description Jacob likes to play wit ...

  7. 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 ...

  8. 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 ...

  9. UVA1623-Enter The Dragon(并查集)

    Problem UVA1623-Enter The Dragon Accept: 108  Submit: 689Time Limit: 3000 mSec Problem Description T ...

随机推荐

  1. 在模仿中精进数据分析与可视化01——颗粒物浓度时空变化趋势(Mann–Kendall Test)

      本文是在模仿中精进数据分析与可视化系列的第一期--颗粒物浓度时空变化趋势(Mann–Kendall Test),主要目的是参考其他作品模仿学习进而提高数据分析与可视化的能力,如果有问题和建议,欢迎 ...

  2. 重新整理 mysql 基础篇————— 事务隔离级别[四]

    前言 简单介绍一下事务隔离的基本 正文 Read Uncommitted(未提交读) 这个就是读未提交.就是说在事务未提交的时候,其他事务也可以读取到未提交的数据. 这里举一个例子,还是前一篇的例子. ...

  3. LeetCode:322. 零钱兑换

    链接:https://leetcode-cn.com/problems/coin-change/ 标签:动态规划.完全背包问题.广度优先搜索 题目 给定不同面额的硬币 coins 和一个总金额 amo ...

  4. RobotFramework + Python 自动化入门 一 (从这里开始)

    一.环境搭建 1. 安装Python Python3会自动配置path,安装pip工具(python包安装和管理工具) 2. 安装robotframework library cmd窗口安装命令: p ...

  5. 在js中使用moment将秒转换为多少天多少小时多少分多少秒

    let x = 2703750;//单位是秒 var d = moment.duration(x, 'seconds'); console.log(Math.floor(d.asDays()) + ' ...

  6. vue中使用element-ui出现Couldn't find preset "es2015" relative to directory

    这是因为没有安装ES 标准 使用 npm install babel-preset-es2015 -d 安装之后就好了

  7. OpenGL 实用攻关 001 准备(开题)

    开篇 这里是OpenGL学习中的随笔,会大致讲述定下的目标需求,思路和贴出认为的关键代码以及git仓库地址.会选择性的讲述途中遇到的陷阱,和注意点. 一些资源 笔者是windows 操作系统 VS 2 ...

  8. bootstrap validate 验证插件 动态添加和动态删除验证项

    //添加验证项 function addField(field, notEmptyMsg, othercon) { if (!othercon) { $("#gyssave").b ...

  9. AcWing 828. 模拟栈

    实现一个栈,栈初始为空,支持四种操作: (1) "push x" – 向栈顶插入一个数x: (2) "pop" – 从栈顶弹出一个数: (3) "em ...

  10. Prometheus(一):Web服务环境监控

    写在前面 现每个后端的同学的日常都在跟服务(接口)打交道,维护老的比较大单体应用.按业务拆得相对比较细的新服务.无论企业内部用的,面向用户的前端的服务.流量大的有流量小的,有重要的有不那么重要的. 但 ...