【题目链接】

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. VC常用代码之创建进程

    作者:朱金灿 来源:http://blog.csdn.net/clever101 创建进程是编程开发的常用操作.Windows中的创建进程采用API函数CreateProcess实现.下面是一个使用例 ...

  2. Beta冲刺-星期四

    这个作业属于哪个课程  <课程的链接>            这个作业要求在哪里 <作业要求的链接> 团队名称 Three cobblers 这个作业的目标 完成今天的冲刺 一 ...

  3. 使用T-sql建库建表建约束

    为什么要使用sql语句建库建表? 现在假设这样一个场景,公司的项目经过测试没问题后需要在客户的实际环境中进行演示,那就需要对数据进行移植,现在问题来了:客户的数据库版本和公司开发阶段使用的数据库不兼容 ...

  4. cmd 运行 svn 亲测!!!

    如果之前安装了svn客户端,但是一直提示svn停止工作的话就可以用cmd去操作svn更新和提交了:或者可以直接用别的代码IDE(包含svn插件的)去进行svn的操作. 接下来我说说windows如何用 ...

  5. UNIX SOCKET编程简介

    1  .  Layered Model of Networking Socket  编程的层次模型如下图所示,   最上面是应用层,应用层下面的是  SOCKET API  层,再下面是传输层和网络层 ...

  6. MAMP PRO php的session保存在哪里

    session的概念就不介绍了,最近接触php,很好奇session会保存在哪里. mac上用了MAMP PRO集成环境,作为服务器. 查了网上,说session的保存路径在php.ini中声明,于是 ...

  7. Can't find variable: SockJS vue项目

    用的vue-cli(webpack-simple模板),在开发环境运行(npm run dev),一直都没有问题,突然在ios的safari中调试,出现报错:Can't find variable: ...

  8. X509 颁发者和使用者 详解

    CN=公用名称C=国家ST=省份L =城市或者区域O=组织名称OU=组织单位名称

  9. 05-Linux系统编程-第02天(文件系统、目录操作、dup2)

    1 课程回顾 02-文件存储 文件名不在inode里 而是保存在一个叫dentry的结构体里了 格式化就是指定一组规则 指定对文件的存储及读取的一般方法 linux下主要使用 ext2 ext3 ex ...

  10. 《奋斗吧!菜鸟》 第八次作业:Alpha冲刺 Scrum meeting 2

    项目 内容 这个作业属于哪个课程 任课教师链接 作业要求 https://www.cnblogs.com/nwnu-daizh/p/11012922.html 团队名称 奋斗吧!菜鸟 作业学习目标 A ...