1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛

Description

经过跟Farmer John长达数年的谈判,奶牛们终于如愿以偿地得到了想要的旱冰鞋。农场上大部分的区域都很平整,适合在上面滑动,但有一些小块的土地上有很多的岩石,凭奶牛们的旱冰技术,是没有办法通过的。 农场可以看成一个被划分成R(1<=R<=113)行C(1<=C<=77)列的矩阵。快要开饭了,贝茜发现自己在坐标为(1,1)的格子里,并且她想赶到坐标为(R,C)的牛棚去享用她的晚饭。贝茜知道,以她所在的格子为起点,每次向上、下、左、右滑动(但不能沿对角线滑动),一定能找到一条通往牛棚的、不经过任何有大量岩石的格子的路。请你为她指出任意一条通往牛棚的路径。

妈的傻逼题做这么长时间,真TM菜。

一开始写Dij写挂了,现在回想就是数组开小了,之后写大法师还T。

正解BFS记录路径,当一个模板记。

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; inline int read(){
int sum=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){sum=(sum<<1)+(sum<<3)+ch-'0'; ch=getchar();}
return sum*f;
} const int wx=517; struct node{
int x,y;
}; int dx[]={0,1,0,-1,0};
int dy[]={0,0,1,0,-1}; int vis[wx][wx];
int a[wx][wx],ansx[wx],ansy[wx];
char c[wx];
int prex[wx][wx];int prey[wx][wx];
int n,m,ans,num,tot,cnt;
int xx[wx],yy[wx],dis[wx][wx]; queue<node >q; void bfs(){
memset(dis,0x3f,sizeof dis);
dis[1][1]=0; q.push((node){1,1});
while(q.size()){
int ux=q.front().x; int uy=q.front().y;
q.pop();
for(int i=1;i<=4;i++){
int ex=ux+dx[i]; int ey=uy+dy[i];
if(ex<1||ex>n||ey<1||ey>m||a[ex][ey])continue;
if(dis[ex][ey]>dis[ux][uy]+1){
dis[ex][ey]=dis[ux][uy]+1;
q.push((node){ex,ey});
prex[ex][ey]=ux; prey[ex][ey]=uy;
}
}
}
} int main(){
n=read(); m=read();
for(int i=1;i<=n;i++){
scanf("%s",c+1);
for(int j=1;j<=m;j++){
a[i][j]=(c[j]=='*');
}
}
bfs();
int nowx=n; int nowy=m;
while(nowx){
ansx[++tot]=nowx; ansy[tot]=nowy;
int tmp=nowx;
nowx=prex[tmp][nowy]; nowy=prey[tmp][nowy];
}
for(int i=tot;i>=1;i--){
printf("%d %d\n",ansx[i],ansy[i]);
}
return 0;
}

BFS【bzoj1667】: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛的更多相关文章

  1. BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛

    1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 665  Solved: 419 ...

  2. BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )

    裸的LIS ----------------------------------------------------------------- #include<cstdio> #incl ...

  3. BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5 ...

  4. BZOJ1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富

    1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 459  Sol ...

  5. BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富( dp )

    dp , dp[ i ][ j ] = max( dp[ k ][ j - 1 ] ) + G[ i ][ j ] ( i - 1 <= k <= i + 1 , dp[ k ][ j - ...

  6. 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富

    1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 498  Sol ...

  7. bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MB Description 为了防止 ...

  8. bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘

    1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec  Memory Limit: 64 MB Submit: 387  Sol ...

  9. BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包

    BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...

随机推荐

  1. Scala的Json序列化

    import java.util.TimeZone import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMappe ...

  2. ruby中nil?, empty? and blank?

    In Ruby, you check with nil? if an object is nil: article = nil article.nil? # => true empty? che ...

  3. 2015.1.4 判断鼠标点击DataGridView的第几行还是空白处

    public int GetRowIndexAt(int mouseLocation_Y) { if (dvaw.FirstDisplayedScrollingRowIndex < 0) { r ...

  4. 第三章 Java内存模型(下)

    锁的内存语义 中所周知,锁可以让临界区互斥执行.这里将介绍锁的另一个同样重要但常常被忽视的功能:锁的内存语义 锁的释放-获取建立的happens-before关系 锁是Java并发编程中最重要的同步机 ...

  5. python(时间模块,序列化模块等)

    一.time模块 表示时间的三种方式: 时间戳:数字(计算机能认识的) 时间字符串:t='2012-12-12' 结构化时间:time.struct_time(tm_year=2017, tm_mon ...

  6. myeclipse与eclipse的web项目部署区别

    一.myeclipse之web项目的部署(发布)流程 web项目的部署(发布)流程2008-01-18 14:35 在myeclipse下新建web工程abc.系统设置默认如下: 项目保存位置:wor ...

  7. DAY19-Django之form组件补充

    问题1:注册页面输入为空,报错:keyError:找不到password def clean(self): print("---" ,self.cleaned_data) # if ...

  8. Javascript 面向对象(一):封装

    Javascript 面向对象编程(一):封装 Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言, ...

  9. ionic 页面乱码

    是文本编辑器的问题.文本编辑器保存时默认保存成Encoding:ANSI编码格式,保存成utf-8就好了

  10. MyBatis总结二:增删改查

    上一篇讲述了MyBatis的快速入门,下面在此基础上进行增删改查的操作: 首先定义dao层的接口: package com.zy.dao; import com.zy.domain.User; imp ...