【题目链接】

http://poj.org/problem?id=2044

【算法】

广度优先搜索

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 400
const int dx[] = {,-,-,,,,,,};
const int dy[] = {,,,-,-,,,,}; int i,j,k,n;
int a[MAXN][][];
bool visited[][][MAXN][][][][]; struct info
{
int x,y,day;
int s1,s2,s3,s4;
};
inline bool check(int x,int y,int day,int s1,int s2,int s3,int s4)
{
if (x <= || x > || y <= || y > ) return false;
if (a[day][x][y] == ) return false;
if (a[day][x][y+] == ) return false;
if (a[day][x+][y] == ) return false;
if (a[day][x+][y+] == ) return false;
if (s1 >= || s2 >= || s3 >= || s4 >= ) return false;
return true;
}
inline bool bfs()
{
int i,sa,sb,sc,sd,tx,ty;
queue< info > q;
info cur;
if (a[][][] || a[][][] || a[][][] || a[][][]) return false;
memset(visited,false,sizeof(visited));
while (!q.empty()) q.pop();
q.push((info){,,,,,,});
visited[][][][][][][] = true;
while (!q.empty())
{
cur = q.front();
q.pop();
if (cur.day == n) return true;
for (i = ; i < ; i++)
{
tx = cur.x + dx[i];
ty = cur.y + dy[i];
sa = cur.s1 + ;
sb = cur.s2 + ;
sc = cur.s3 + ;
sd = cur.s4 + ;
if (tx == && ty == ) sa = ;
if (tx == && ty == ) sb = ;
if (tx == && ty == ) sc = ;
if (tx == && ty == ) sd = ;
if (check(tx,ty,cur.day+,sa,sb,sc,sd) && !visited[tx][ty][cur.day+][sa][sb][sc][sd])
{
q.push((info){tx,ty,cur.day+,sa,sb,sc,sd});
visited[tx][ty][cur.day+][sa][sb][sc][sd] = true;
}
}
}
return false;
} int main()
{ while (scanf("%d",&n) != EOF && n)
{
for (i = ; i <= n; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= ; k++)
{
scanf("%d",&a[i][j][k]);
}
}
}
if (bfs()) printf("%d\n",);
else printf("%d\n",);
} return ; }

【POJ 2044】 Weather Forecast的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. 富文本wangEditor的批量激活

    最近项目中使用了wangEditor这个轻量级的富文本框,由于需求是一个页面中会有多个富文本框同时激活,所以写了个批量激活的jquery方法,分享一下 // 激活富文本框 var wangEditor ...

  2. 如何通过putty软件远程登录并且控制linux平台

    准备备工作: 下载putty远程登录软件,图标如下 打开linux主机. Linux主机准备条件: 1 配置IP ,如果大家使用虚拟机的话建议通过vm1或者vm8进行与本地真实机进行连接,同时注意要避 ...

  3. Linux while和for循环简单分析

    一.循环重定向 最近遇到了一种新的循环重定向写法,由于没看懂,说以网上搜索了一下,然后再此分享一下: while read line do ...... done  < file 刚开始看,不明 ...

  4. 在 ef 中执行 DbContext.Table.AddRange(Enitites).ToList() 会发生什么

    在 ef 中执行 DbContext.Table.AddRange(Enitites).ToList() 会发生什么 昨天和朋友摸鱼,无意之间聊到了执行 DbContext.Table.AddRang ...

  5. Centos6.6 安装Redis

    一.介绍 redis在做数据库缓存,session存储,消息队列上用的比较多 二.安装 $ yum install -y wget gcc make tcl $ wget http://downloa ...

  6. Why use Cache-Control header in request?

    本地缓存也是缓存代理的一部分. 请求时使用Cache-Control 表示缓存的使用策略. 请求头里的no-cache表示浏览器不想读缓存,并不是说没有缓存.一般在浏览器按ctrl+F5强制刷新时,请 ...

  7. HTML 1.1页面js修改文字颜色

    昨天的报告页面,想要实现根据不同文字内容改变字体颜色,效果图: 调试了半天出不来效果,最后请教了前端,上代码: <!DOCTYPE html> <html lang="en ...

  8. java环境搭建心得

     右击此电脑,点击属性, 在打开的电脑系统对话框里发电机i直接点击左侧导航里的[高级系统设置]在打开的电脑系统属性对话框里直接点击下面的[环境变量] 打开环境变量对话框后,直接点击系统变量下面的新建, ...

  9. 基于分布式框架 Jepsen 的 X-Cluster 正确性测试

    转自:https://mp.weixin.qq.com/s/iOe1VjG1CrHalr_I1PKdKw 原创 2017-08-27 严祥光(祥光) 阿里巴巴数据库技术 1 概述 AliSQL X-C ...

  10. php第八节课

    加载 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...