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


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

每个状态要存当前坐标、天数和这个状态下四个角的情况,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. zabbix 发现 vmvare esxi6.7 虚拟主机

    1:服务端配置确认 确保 #vi /etc/zabbiz/zabbix-server/zabbix_server.conf ## 确认其中有 StartVMwareCollectors项目 值 > ...

  2. redis不完整的事务实现Transaction

    使用场景 redis一个命令执行是单线程的,不用担心并发冲突,如果你想有几个命令想像一个命令一样,在这几个命令执行过程中不会执行别的客户端发来的命令 ,也就是原子性,就可以用 redis Transa ...

  3. Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇)

    Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇) 目录 Mysql优化(出自官方文档) - 第十二篇(优化锁操作篇) 1 Internal Locking Methods Row-Leve ...

  4. Map类型的Json格式

    示例代码: Map<String, Object> map = new HashMap<>();// boolean 类型 map.put("boolean" ...

  5. Java安全之基于Tomcat实现内存马

    Java安全之基于Tomcat实现内存马 0x00 前言 在近年来红队行动中,基本上除了非必要情况,一般会选择打入内存马,然后再去连接.而落地Jsp文件也任意被设备给检测到,从而得到攻击路径,删除we ...

  6. Pytest学习笔记8-参数化

    前言 我们在实际自动化测试中,某些测试用例是无法通过一组测试数据来达到验证效果的,所以需要通过参数化来传递多组数据 在unittest中,我们可以使用第三方库parameterized来对数据进行参数 ...

  7. kubernetes的存活探针和就绪探针

    1.存活探针 使用Kubernetes的一个主要好处是,可以给Kubernetes-个容器列表来由其保持容器在集群中的运行.可以通过让Kubernetes创建pod资源,为其选择一个工作节点并在该节点 ...

  8. 记一次ios下h5页面图片显示问题

    刚入职公司时做了一个移动端图片预览的组件,之前也有业务组用过,没发现什么问题,但是这次有两个很诡异的问题. 一个是老数据的图不显示,另一个是图片点击预览只显示一部分加载不全.之所以诡异是所有设备都没问 ...

  9. CentOS-yum安装chrome+chromeDriver+xvfb

    安装chrome 创建yum源文件 $ vim /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseu ...

  10. head tail 用法

    tail 显示最后几行,-n后面的数字无符号,表示行数 tail -n 1000:显示最后1000行 tail -n +1000:从1000行开始显示到最后 tail -n -1000:从负1000行 ...