【题目链接】

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. [转]深入javascript——原型链和继承

    在上一篇post中,介绍了原型的概念,了解到在javascript中构造函数.原型对象.实例三个好基友之间的关系:每一个构造函数都有一个“守护神”——原型对象,原型对象心里面也存着一个构造函数的“位置 ...

  2. 20小时掌握网站开发(免费精品htmlcss视频教程)

    自己最近研发了一套新的htmlcss教程,并进行了授课实施,视频教程百度云下载链接如下: 视频及案例源码下载地址 本套教程视频需要安装屏幕录像专家软件才能观看,屏幕录像专家下载地址如下: 屏幕录像专家 ...

  3. Dynamics CRM查询实体共享给哪些人

    在mscrm中,如果想查询一条记录共享给了哪些人,需要用到PrincipalObjectAccess 表,sql如下: select u.FullName,a.RC_name,sup.SystemUs ...

  4. java Web(2)

    Servlet与web容器的配合: 1)客户端向Web服务器发起一个HTTP请求. 2)HTTP请求被Web服务器接受,如果请求的是静态页面,则由Web服务器负责处理.如果请求的是Java Web组件 ...

  5. 装X数学:高雅的数学表示

    采用高雅的数学描述 转自于:研究生之路怎么走?       高雅的数学描述会提高你论文的等级和加强评审人对你基础功底的认可.例如泛函分析.集合.测度.度量空间和拓扑空间.现代代数.微分几何等数学方面的 ...

  6. logger日志

    Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调试 ERROR 错误事件可能仍然允许应用程序继续运行 FATAL 指定非常严重的错误事件,这可能导致应用 ...

  7. APICloud上啦加载下拉刷新模块

    apicloud有自带的上啦加载下拉刷新,当让也可以用第三方或者在模块库里面找一个使用 一.下拉刷新,一下代码写在 apiready = function (){} 里面 apiready = fun ...

  8. unittest的case和报告生成方法

    #coding=utf-8from appium import webdriverimport unittestimport HTMLTestRunnerclass CaseTest(unittest ...

  9. Java 实现邮件发送功能

    1.新建model SendMail.java import java.util.Properties; public class SendMail { // 发送邮件的服务器的IP和端口 priva ...

  10. 程序包管理rpm和yum

    Linux程序包管理: API:Application Programming Interface源码包 POSIX:Portable OS 程序源代码 --> 预处理 --> 编译 -- ...