http://www.lydsy.com/JudgeOnline/problem.php?id=1632

我简直是个sb。。。

。。。

bfs都不会写。。

算方案还用2个bfs!

都不会整合到一个!

然后赤裸裸的wa了。

然后对拍。。。

果然错的地方很。。。

。。

然后貌似自己想改bfs,只需一个就行了。。

而且方案也改对了????

然后不知哪里写挫了。。。然后样例过不了了。。

然后无奈看别人题解了。。。

QAQ

噗,方案和我想的一样,但是。。。。。。。。。。。。。。。我忘记了个东西,,标记啊。。

噗。。我尽然没标记。。。怪不得。。

吐槽完毕。。

这个bfs的时候更新很简单的。

自己看看就懂了的。。只要记住要标记!!!!要不然答案会大得离奇

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j] << '\t'; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=35, Q=10000, dx[]={-1, -2, -2, -1, 1, 2, 2, 1}, dy[]={-2, -1, 1, 2, 2, 1, -1, -2};
int mp[N][N], f[N][N], d[N][N], vis[N][N], n, m, X, Y, XX, YY, front, tail;
struct dat { int x, y; }q[Q];
long long p[N][N]; void bfs1() {
front=tail=0;
q[tail].x=X, q[tail].y=Y; ++tail;
CC(f, 0x3f); CC(d, 0x3f); f[X][Y]=d[X][Y]=0; vis[X][Y]=p[X][Y]=1;
while(front!=tail) {
dat &t=q[front++]; if(front==Q) front=0;
int x=t.x, y=t.y; vis[x][y]=0;
if(x==XX && y==YY) continue;
rep(i, 8) {
int fx=dx[i]+x, fy=dy[i]+y;
if(fx<1 || fy<1 || fx>n || fy>m || mp[fx][fy]==2) continue;
dat &t2=q[tail];
int add=mp[fx][fy]==0;
if(f[fx][fy]>f[x][y]+add) {
f[fx][fy]=f[x][y]+add;
d[fx][fy]=d[x][y]+1;
p[fx][fy]=p[x][y];
if(!vis[fx][fy]) t2.x=fx, t2.y=fy, vis[fx][fy]=1; if(++tail==Q) tail=0;
}
else if(f[fx][fy]==f[x][y]+add && d[fx][fy]>d[x][y]+1) {
d[fx][fy]=d[x][y]+1;
p[fx][fy]=p[x][y];
if(!vis[fx][fy]) t2.x=fx, t2.y=fy, vis[fx][fy]=1; if(++tail==Q) tail=0;
}
else if(f[fx][fy]==f[x][y]+add && d[fx][fy]==d[x][y]+1) {
p[fx][fy]+=p[x][y];
if(!vis[fx][fy]) t2.x=fx, t2.y=fy, vis[fx][fy]=1; if(++tail==Q) tail=0;
}
}
}
}
int main() {
read(n); read(m);
for1(i, 1, n) for1(j, 1, m) {
int t=getint(); mp[i][j]=t;
if(t==3) X=i, Y=j; else if(t==4) XX=i, YY=j;
}
bfs1();
if(f[XX][YY]==0x3f3f3f3f) puts("-1");
else printf("%d\n%d\n%lld\n", f[XX][YY], d[XX][YY], p[XX][YY]);
return 0;
}

【BZOJ】1632: [Usaco2007 Feb]Lilypad Pond(bfs)的更多相关文章

  1. 【BZOJ】1631: [Usaco2007 Feb]Cow Party(dijkstra)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1631 看到m<=100000果断用dij(可是好像dij比spfa还慢了在这里?)//upd: ...

  2. 【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> # ...

  3. 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...

  4. 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...

  5. BZOJ 1632: [Usaco2007 Feb]Lilypad Pond

    题目 1632: [Usaco2007 Feb]Lilypad Pond Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 390  Solved: 109[ ...

  6. 1632: [Usaco2007 Feb]Lilypad Pond

    1632: [Usaco2007 Feb]Lilypad Pond Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 404  Solved: 118[Sub ...

  7. BZOJ 1632 [Usaco2007 Feb]Lilypad Pond:spfa【同时更新:经过边的数量最小】【路径数量】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1632 题意: 有一个n*m的池塘.0代表水,1代表荷花,2代表岩石,3代表起点,4代表终点 ...

  8. 【BZOJ】1697: [Usaco2007 Feb]Cow Sorting牛排序

    [算法]数学置换 [题意]给定n个数,要求通过若干次交换两个数的操作得到排序后的状态,每次交换代价为两数之和,求最小代价. [题解] 考虑置换的定义:置换就是把n个数做一个全排列. 从原数组到排序数组 ...

  9. 【BZOJ】3053: The Closest M Points(kdtree)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!! ...

随机推荐

  1. hdu4515小Q系列故事——世界上最遥远的距离

    Problem Description 世界上最遥远的距离 不是生与死 而是我就站在你面前 你却不知道我爱你 世界上最遥远的距离 不是我就站在你面前你却不知道我爱你 而是明明知道彼此相爱 却不能在一起 ...

  2. Hadoop-2.4.1学习之Streaming编程

    在之前的文章曾提到Hadoop不仅支持用Java编写的job,也支持其他语言编写的作业,比方Hadoop Streaming(shell.python)和Hadoop Pipes(c++),本篇文章将 ...

  3. ZK框架笔记5、事件

            事件是org.zkoss.zk.ui.event.Event类,它通知应用程序发生了什么事情.每一种类型的事件都由一个特定的类来表示.         要响应一个事件,应用程序必须为事 ...

  4. js实现图片的等比例缩放

      js实现图片的等比例缩放 CreateTime--2018年3月6日14:04:18 Author:Marydon 1.代码展示 /** * 图片按宽高比例进行自动缩放 * @param ImgO ...

  5. IBATIS+ORACLE(一)

      迁移时间:2017年6月1日15:55:17 Author:Marydon (四)IBATIS + ORACLE 第一部分:基础篇 1.4.1.1 分页SQL <!-- 开头 --> ...

  6. loadrunner参数使用总结

    使用loadrunner进行性能测试,在准备脚本阶段参数是不可避免要使用到的,现把参数的各种设置取值方式总结一下,方便日后查阅: update value on Sequential顺序取值下的取值结 ...

  7. Cacti监控mysql数据库服务器实现过程

    Cacti监控mysql数据库服务器实现过程 2014-05-29      0个评论    来源:Cacti监控mysql数据库服务器实现过程   收藏    我要投稿 1 先在cacti服务器端安 ...

  8. Nutch的发展历程(转)

    2002年8月由Doug Cutting发起,托管于Sourceforge,之后发布了0.4.0.5.0.6三个版本 2004年9月Oregon State University(俄勒冈州立大学)采用 ...

  9. B2C电子商务系统研发——产品媒体常见功能点

    产品媒体常见功能点 电商研发系列——产品媒体常见功能点 支持图片.视频和文档等媒体类型 产品图片对清晰度要求比极高,但又不能太大,所以图片一般是jpg格式. 视频一般是flv流媒体格式,如果是嵌入产品 ...

  10. Grunt快速使用笔记

    本篇文章由:http://xinpure.com/grunt-quick-note/ http://www.gruntjs.net/getting-started Grunt中文网 安装 Grunt ...