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. 某个应用使cpu使用率100%

    --CPU使用率 Linux是一个多任务的操作系统,将每个cpu的时间划分为很短的时间片,再通过调度器轮流分配给各个任务使用,因此造成多任务同时运行的错觉 为了维护cpu时间,linux通过事先定义的 ...

  2. 使用Fiddler进行iOS APP的HTTP/HTTPS抓包

    Fiddler不但能截获各种浏览器发出的HTTP请求, 也可以截获各种智能手机发出的HTTP/HTTPS请求.Fiddler能捕获IOS设备发出的请求,比如IPhone, IPad, MacBook. ...

  3. malloc 动态分配内存

    很久没有学习C了,复习下,有时候觉的C特别优美,学习算法和数据结构最佳选择. #include "stdafx.h" #include<stdlib.h> int ma ...

  4. leetcode860

    使用C++进行编码: bool lemonadeChange(vector<int>& bills) { ; ; ; int N = bills.size(); ; i < ...

  5. chrome开发者工具的使用

    转自:https://blog.csdn.net/csdnligao/article/details/53925094

  6. (修改)oracle11g监听多台主机配置,用pl/sql连接操作多个数据库详解

    很多朋友在开发项目中并不是每个人用一个数据库,而是有单独的一台主机作为开发的数据库服务器,这样,就需要我们的开发人员去连接它. 首先是进入oracle的 Net  Mananger:

  7. DHCP工作工程

    1.客户端请求IP 客户端发一个DHCP DISCOVEY(包含主机名.mac地址)广播包 2.服务端响应请求 DHCP服务器收到请求后,查看自己的地址池是否有合法的地址.如果有,广播一个DHCP o ...

  8. 安装完Ubuntu 14.04后的几件事

    周末折腾一下Ubuntu 14.04,稍作记录: 1. 切换源,我还是钟情163的(ps, 这里如果用的以前13.04时候163的源会有问题,记得配置最新的http://mirrors.163.com ...

  9. cfree使用cygwin编译程序出现计算机丢失cygwin1.dll解决办法

    这种情况多是环境没配好,我的是64位cygwin C:\cygwin64\bin 加入到环境变量中,重打开cfree就可以解决.

  10. oracle DML-(insert、select、update、delete)

    一.插入记录INSERT INTO table_name (column1,column2,...) values ( value1,value2, ...); 示例:insert into emp ...