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. 2016.1.19 DEV Express控件GirdControl使用

    103.GridControl中添加Button RunDesigner,添加一列,设置对应字段FiledName,ColumnEdit选择ButtonEdit,此时默认风格像下拉框,需调整属性: 在 ...

  2. oracle 密码默认180天过期

    alter profile default limit password_life_time unlimited; alter user username identified by 'pwd';

  3. 设置mysql表名大小写不敏感

    在跨平台的程序设计中要注意到mysql的一些系统变量在windows和linux上的缺省值是不同的, 比如mysql表名称的大小写变量. 在windows上lower_case_table_names ...

  4. 阿里云服务器ubuntu安装redis2.8.13

    阿里云服务器ubuntu安装redis2.8.13 2014-09-04 16:14 |  coding云 |  2198次阅读 | 暂无评论   一.下载redis 可以先下载到本地,然后ftp到服 ...

  5. 监控和安全运维 1.3 cacti增加客户端监控

    二. 安装客户端(增加一个linux服务器) 1.在客户端上 安装snmp yum install -y net-snmp 2. 修改snmpd.conf vim /etc/snmp/snmpd.co ...

  6. nested exception is java.net.UnknownHostException: mybatis.org异常处理

    最近自己写了个小项目(丛林商城V1.0),一个简单的网上商铺:主界面是商品的展示和登录,面对三种角色的人群:一般客户,VIP客户,管理员,与之对应的三种商品价格,登陆后根据具体角色来显示商品的价格:还 ...

  7. 解决Xcode在debug时不在断点处停止的方法<转>

    搞了老半天不知道为什么 后来查了一下才解决问题,多谢原创作者的贡献. 新年后的第一发! -------------------------------- 前几天在开发的时候,Xcode设置断点后依然无 ...

  8. CSS制作水平垂直居中对齐 多种方式各有千秋

    作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收 集了几种不同的方式制作垂直居中方法,但每种方法各有千秋 ...

  9. js对象简单、深度克隆(复制)

    javascript的一切实例都是对象,只是对象之间稍有不同,分为原始类型和合成类型.原始类型对象指的是字符串(String).数值(Number).布尔值(Boolean),合成类型对象指的是数组( ...

  10. ListView里面嵌套CheckBox

    布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro ...