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


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

每个状态要存当前坐标、天数和这个状态下四个角的情况,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. 菜鸟刷题路(随缘刷题):leetcode88

    lc88 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int i = m - 1, j = ...

  2. Redisson 分布式锁实现之前置篇 → Redis 的发布/订阅 与 Lua

    开心一刻 我找了个女朋友,挺丑的那一种,她也知道自己丑,平常都不好意思和我一块出门 昨晚,我带她逛超市,听到有两个人在我们背后小声嘀咕:"看咱前面,想不到这么丑都有人要." 女朋友 ...

  3. QueryTable的使用以及错误

    1.QuerySeter的filter使用遇到的错误 1.1 Filter里的字段名和操作符要用双下划线."__" 不是" _",否则会被认为成是列名的一部分, ...

  4. OpenResty高并发

    在电商项目中所有的访问都是通过首页访问进去的,那么首页门户的访问频率会是非常高的,用我们专业术语来说就是并发量高,这时问题就来了,并发量高我们在做程序时就要保证首页的抗压能力强,而且还要保证抗压的同时 ...

  5. jenkins在aws eks中的CI/CD及slave

    本文档不讲解jenkins的基础用法,主要讲解配合k8s的插件,和pipeline的用途和k8s ci/cd的流程. 以及部署在k8s集群内和集群外的注意事项. 1.准备工作 以下在整个CI/CD流程 ...

  6. 美化terminal时碰到的问题- Set-Theme

    报错: 1 Set-Theme Set-Theme: The term 'Set-Theme' is not recognized as a name of a cmdlet, function, s ...

  7. Java基础之(一)——从synchronized优化看Java锁概念

    一.悲观锁和乐观锁概念 悲观锁和乐观锁是一种广义的锁概念,Java中没有哪个Lock实现类就叫PessimisticLock或OptimisticLock,而是在数据并发情况下的两种不同处理策略. 针 ...

  8. Java数据库开发(二)之——DBCP连接数据库

    1.载入jar包 DBCP需要以下几个jar包,可到apache及mysql的官网下载 2.程序编写 public static BasicDataSource ds = null; static f ...

  9. Channel Allocation 贪心涂色

    Channel Allocation 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> ...

  10. Redis 底层数据结构之链表

    文章参考:<Redis设计与实现>黄建宏 链表 链表提供了高效的节点重排能力,以及可以顺序访问,也可以通过增删节点灵活调整链表长度,Redis中的列表.发布订阅.慢查询.监视器等功能均用到 ...