[bzoj2574] [Poi1999]Store-Keeper
坑啊。。
膜了半天byvoid大爷的题解。https://www.byvoid.com/blog/poi-1999-mag/?replytocom=1335/
一开始从人的位置bfs一波,看看能走到初始包裹哪些方向上。要注意不能穿过初始包裹...byvoid的标程在处理穿过包裹什么的地方有问题...但数据略弱。
之后如题解所述。
发现自己不会求点双连通分量QAQ。。那部分就抄标程了...
大概就是记录一下当前走过的边,遇到割点就一直出栈...和求强连通分量差不多,就是一个点可能在多个点双里面..这个比较烦
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const int xx[]={-,,,},yy[]={,,-,};
struct zs{int too,pre;}e[maxn<<];int tot,last[maxn];
int too[],pre[],la[maxn],tt,st1[maxn],top,cnt,st2[maxn],uuu[][][][];bool uu[maxn];
struct poi{int x,y;}S,T,M;
struct zs1{int x,y,dir;}dl[maxn<<];
int dfn[maxn],low[maxn],tim;
bool gd[maxn],u[maxn];
int id[][],dis[][][],q[maxn];
char mp[][];
int i,j,k,n,m,man,st,ed; inline void ins(int a,int b){
int i=la[a];
while(i&&too[i]!=b)i=pre[i];
if(i)return;
too[++tt]=b,pre[tt]=la[a],la[a]=tt;
}
inline bool same(int a,int b){
int i;bool flag;
for(i=la[a];i;i=pre[i])uu[too[i]]=;
for(i=la[b];i&&!uu[too[i]];i=pre[i]);
flag=i!=;
for(i=la[a];i;i=pre[i])uu[too[i]]=;
return flag;
}
inline bool canget(int x,int y,int dir1,int dir2){
if(!gd[id[x][y]])return ;
if(uuu[x][y][dir1][dir2]<)
return (uuu[x][y][dir1][dir2]=same( id[x+xx[dir1]][y+yy[dir1]] , id[x+xx[dir2]][y+yy[dir2]] ));
else return uuu[x][y][dir1][dir2];
}
void tarjan(int x,int fa){
dfn[x]=low[x]=++tim;int too,u,v;
for(int i=last[x];i;i=e[i].pre)if(dfn[e[i].too]<dfn[x]){
too=e[i].too;
if(!dfn[too]){
st1[++top]=x,st2[top]=too;
tarjan(too,x),low[x]=min(low[x],low[too]);
if(low[too]>=dfn[x]){
gd[x]=;
cnt++;
do{
u=st1[top],v=st2[top],
ins(u,cnt),ins(v,cnt),top--;
}while((u!=x||v!=too)&&(u!=too||v!=x));
}
}
else low[x]=min(low[x],dfn[e[i].too]);
}
} inline void insert(int a,int b){
e[++tot].too=b,e[tot].pre=last[a],last[a]=tot,
e[++tot].too=a,e[tot].pre=last[b],last[b]=tot;
} inline bool check(int x,int y){return x>&&y>&&x<=n&&y<=m&&mp[x][y]!='S';} inline void bfs(int s){
int l=,r=,i,now;q[]=s,u[s]=;
while(l<r)
for(i=last[now=q[++l]];i;i=e[i].pre)if(!u[e[i].too]&&e[i].too!=st)
u[e[i].too]=,q[++r]=e[i].too;
}
inline int run(){
int l=,r=,i,nx,ny,ndir,ndis,x,y;
for(i=;i<;i++){
x=S.x+xx[i],y=S.y+yy[i];
if(check(x,y)&&u[id[x][y]])dl[++r]=(zs1){S.x,S.y,i},dis[S.x][S.y][i]=;//,printf("st:%d,%d\n",x,y);
}
while(l<r){
l++,nx=dl[l].x,ny=dl[l].y,ndir=dl[l].dir,ndis=dis[nx][ny][ndir];
x=nx+xx[ndir^],y=ny+yy[ndir^];//printf("case:%d,%d dis:%d dir:%d\n",nx,ny,ndis,ndir);
if(!check(x,y))continue;
if(x==T.x&&y==T.y)return ndis;
for(i=;i<;i++)
if(check(x+xx[i],y+yy[i])&&!dis[x][y][i]&&canget( x,y,ndir,i ))
dis[x][y][i]=ndis+,dl[++r]=(zs1){x,y,i};
}
return -;
}
int main(){
memset(uuu,,sizeof(uuu));
scanf("%d%d",&n,&m);int tmp=;tot=;
for(i=;i<=n;i++){
scanf("%s",mp[i]+);
for(j=;j<=m;j++)if(mp[i][j]!='S'){
id[i][j]=++tmp;
for(k=;k<;k+=){
int x=i+xx[k],y=j+yy[k];
if(check(x,y))
insert(id[i][j],id[x][y]);//,printf("(%d,%d)-->(%d,%d)\n",x,y,i,j);
}
if(mp[i][j]=='M')man=tmp,M=(poi){i,j};
if(mp[i][j]=='P')st=tmp,S=(poi){i,j};
if(mp[i][j]=='K')ed=tmp,T=(poi){i,j};
}
}//return 233;
for(i=;i<=tmp;i++)if(!dfn[i])tarjan(i,);
// for(i=1;i<=n;i++)for(j=1;j<=m;j++)if(id[i][j]){
// if(mp[i][j]!='S')printf("(%d,%d) %d fa:%d\n",i,j,id[i][j],getfa(id[i][j]));
// if(gd[id[i][j]])printf(" gd: (%d,%d)\n",i,j);
// }
bfs(man);
int ans=run();
if(ans<)puts("NO");else printf("%d\n",ans);
}
[bzoj2574] [Poi1999]Store-Keeper的更多相关文章
- 如何删除mac keeper
如果不小心安装了mac keeper,基本是无法删除的,而且16年以前的方法都不管用.可以这样删除,我已经测试过了,下载https://data-cdn.mbamupdates.com/web/mba ...
- ZOJ 2601 Warehouse Keeper
Warehouse Keeper Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origin ...
- iOS之App Store上架被拒Legal - 5.1.5问题
今天在看到App Store 上架过程中,苹果公司反馈的拒绝原因发现了这么一个问题: Legal - 5.1.5 Your app uses background location services ...
- 发布APP到app store
好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...
- External Configuration Store Pattern 外部配置存储模式
Move configuration information out of the application deployment package to a centralized location. ...
- redux-devtools 浏览器修改Store值
1. npm install --save-dev redux-devtools 2. npm instal. --redux-devtools-dock-monitor 3. 创建DevTools ...
- NopCommerce 在Category 显示 Store List列表
实现效果如下: 1.在前台Web的Category Menu显示 Store; 2.点击 Store 显示 Store List列表: 3.点击 列表Store 的 Company Name 进入该S ...
- Redux原理(一):Store实现分析
写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何管理stat ...
- 这两天遇到iphone使用app store下载免费软件,必须验证付款信息才能购物是怎么回事???
答案: 在你这台设备上再设置一下,具体方法是:1.点设置进入2.点iTunes Store 和App Store 3.点 Apple ID ,如果没设置,设置一下,如果有的,再点击 4.出现一上选择的 ...
随机推荐
- Oracle数据库(三)表操作,连接查询,分页
复制表 --复制表 create table new_table as select * from Product --复制表结构不要数据 在where后面跟一个不成立的条件,就会仅复制表的结构而不复 ...
- 遍历map的几种方式
1,平时开发中对map的使用很多,然后发现了很多map可能存在的各种问题:如HashMap 需要放置 1024 个元素,由于没有设置容量初始大小,随着元素不断增加,容量 7 次被迫扩大,resize ...
- Ionic2 cordova angular2 打包到Android apk环境搭建
一.前言 前段时间,公司有个APP项目需要支持不同平台,于是采用了Ionic2 + cordova + angular2,在搭建环境过程中遇到了不少问题,刚好最近有时间整理出来. 二.开发环境搭建 参 ...
- ES6 let和const命令(2)
为什么要使用块级作用域 在ES5中只有全局作用域和函数作用域,没有块级作用域,因此带来了这些麻烦 内层变量可能会覆盖外层变量 var tmp = new Date(); console.log(tmp ...
- ABP 教程文档 1-1 手把手引进门之 AngularJs, ASP.NET MVC, Web API 和 EntityFramework(官方教程翻译版 版本3.2.5)含学习资料
本文是ABP官方文档翻译版,翻译基于 3.2.5 版本 转载请注明出处:http://www.cnblogs.com/yabu007/ 谢谢 官方文档分四部分 一. 教程文档 二.ABP 框架 三. ...
- New Life With 2018
2017年转眼过去了.对自己来说.这一大年是迷茫和认知的一年.我的第一篇博客就这样记录下自己的历程吧 一:选择 从进入这一行到现在已经一年多了,2016年11月份就像所有的应届毕业生一样,都贼反感毕业 ...
- http1.0 的哑代理问题
感觉这就和回字的四种写法一样,并无卵用 原以为http1.1的新特性是提供了keep-alive,后来才知道,keep-alive选项http1.1已经不支持了,http1.1对该功能进行了改版 关于 ...
- java多线程(六)-线程的状态和常用的方法
一个线程可以处于以下几种状态之一: (1) 新建(new):当线程被创建时,它只会短暂的处于这种状态,此时它已经获得了必须的系统资源,并执行了初始化,该线程已经有资格获取cpu时间了,之后它将转化为可 ...
- webpack 构建简单的vue项目
---恢复内容开始--- webpack主要执行流程: 入口→loader处理→出口 // webpack.config.js 文件:const path = require('path') // 引 ...
- 初步了解 Django Models
Part1:了解主键 1. Python和Django版本如下: E:\django>python3 -V Python 3.5.2 E:\django>python3 -m d ...