【题目链接】

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. css中background-clip属性的作用

    background-clip属性的通俗作用就是指定元素背景所在的区域,有四种取值 1.border-box border-box是默认值,表示元素的背景从border区域(包括border)以内开始 ...

  2. SQL Server存储过程作业(三)

    阶段4:练习——插入入住客人记录 需求说明 使用存储过程将入住客人信息插入客人信息表中,要求: 检查身份证号必须是18个字符组成 押金的默认值为1000元 如果客人记录插入成功,输出客人流水号:否则输 ...

  3. 4、scala数组

    1.Array 2.ArrayBuffer 3.遍历Array和ArrayBuffer 4.数组常见操作 1.  Array Scala中,array代表的含义与java类似,也是长度不可改变的数组. ...

  4. 我的C++笔记(数据的共享与保护)

    *数据的共享与保护: * .作用域: * 作用域是一个标识符在程序正文中有效的区域.C++中标识符的作用域有函数原型作用域.局部作用域(块作用域).类作用域和命名空间作用域. * ().函数原型作用域 ...

  5. jquery.datatable.js实际运用

    $.dataTablesSettings = { deferRender: true,// 当处理大数据时,延迟渲染数据,有效提高Datatables处理能力 bStateSave: true,//表 ...

  6. javaee IO流作业

    package Zy; import java.io.Serializable; public class Student implements Serializable{ private stati ...

  7. Markdown 常用语法总结

    注意:Markdown使用#.+.*等符号来标记,符号后面必须跟上至少跟上 1个空格才有效! Markdown的常用语法 标题 Markdown标题支持两种形式. 1.用#标记 在标题开头加上1~6个 ...

  8. wafII笔记

    wafII笔记:    组件的使用方法:        组件属性:                 属性的设置和获取通过option方法来完成 waf("#id").wafProm ...

  9. 【剑指Offer】35、数组中的逆序对

      题目描述:   在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P ...

  10. 【JavaScript框架封装】使用原生js封装的类似于JQuery的框架及核心源码分享(多文件版本)

    这个版本的JQuery是对上一个版本的JQuery,使用了require.js进行了二次封装,基本上把前面的每一个框架封装成为一个单独的模块,最终的目录结构如下: 由于代码量和目录比较多,这个封装好的 ...