【POJ 2044】 Weather Forecast
【题目链接】
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- inline-block默认间距解决方法
方法一: 父元素设置font-size: 0; 行内块元素有文字时再在该元素上设置font-size 方法二: 父元素设置word-spacing为负 方法三: Inline-block 元素浮 ...
- Python+selenium第一个自动化脚本
第一个自动化脚本(用Python写的) from selenium import webdriver #从selenium导入webdriber driver=webdriber.Firefox() ...
- 安卓Java读取SD卡文本文件
在进行序列识别时,需要对多个模式串进行识别,需要对多行浮点数进行读取,并进行解析. 所以使用的方法为: 使用文本多行读取的方式:对每行文本进行正则表达式匹配:再进行字符转换. 代码如下: ...
- WebGL绘制三角形
本文程序实现绘制一个三角形的任务,如下图. 整个程序包含两个文件,分别是: 1. HelloTriangle.html <!DOCTYPE HTML PUBLIC "-//W3C//D ...
- uni-app判断各大平台的语法
uni-app是一款强大的前端框架,它除了pc端其他都可以实现,打包原生app.手机h5页面,微信小程序, 但是有一个问题就是本生的app和微信小程序是有一定的区别的,因为app有标题栏,返回键,而微 ...
- BPM结束任务
var pi = tw.system.findProcessInstanceByID("158");for(var i=0; i<pi.tasks.length; i++) ...
- spring boot jpa 无法使用findOne
(findOne(id))说我无法转换成相应的类型,换一种即可,如下: user = userRepository.findOne(id);//spring 2.x用不了 @GetMapping(&q ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- JQuery的click,trigger触发a标签的click事件无效的问题分析
今天在做一个手机端webAPP链接下载的时候,给a标签一个下载链接,但是通过 <a id="downFile" download="" href=&quo ...
- Ubuntu安装RTX2080显卡驱动
安装RTX2080显卡驱动 近日新购了一台DELL服务器,用于TensorFlow,由于显卡是另加的,需要安装显卡驱动. 服务器配置 服务器型号:DELL PowerEdge R730 CPU:2*I ...