坑啊。。

  膜了半天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的更多相关文章

  1. 如何删除mac keeper

    如果不小心安装了mac keeper,基本是无法删除的,而且16年以前的方法都不管用.可以这样删除,我已经测试过了,下载https://data-cdn.mbamupdates.com/web/mba ...

  2. ZOJ 2601 Warehouse Keeper

    Warehouse Keeper Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origin ...

  3. iOS之App Store上架被拒Legal - 5.1.5问题

    今天在看到App Store 上架过程中,苹果公司反馈的拒绝原因发现了这么一个问题: Legal - 5.1.5 Your app uses background location services ...

  4. 发布APP到app store

    好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...

  5. External Configuration Store Pattern 外部配置存储模式

    Move configuration information out of the application deployment package to a centralized location. ...

  6. redux-devtools 浏览器修改Store值

    1. npm install --save-dev redux-devtools 2. npm instal. --redux-devtools-dock-monitor  3. 创建DevTools ...

  7. NopCommerce 在Category 显示 Store List列表

    实现效果如下: 1.在前台Web的Category Menu显示 Store; 2.点击 Store 显示 Store List列表: 3.点击 列表Store 的 Company Name 进入该S ...

  8. Redux原理(一):Store实现分析

    写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何管理stat ...

  9. 这两天遇到iphone使用app store下载免费软件,必须验证付款信息才能购物是怎么回事???

    答案: 在你这台设备上再设置一下,具体方法是:1.点设置进入2.点iTunes Store 和App Store 3.点 Apple ID ,如果没设置,设置一下,如果有的,再点击 4.出现一上选择的 ...

随机推荐

  1. Gulp 的简单使用(原创)

    1.安装nodejs 安装省略 npm的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安 ...

  2. iOS Block的简单使用以及__block 和static修饰变量

    简单的代码总结,不足之处多多指教. //简单的使用 -(void)blockOne{ ; int(^BlockOne)(int) = ^(int num2) { return number*num2; ...

  3. ConcurrentDictionary内部函数的使用说明

    AddOrUpdate(...)函数的使用: private static ConcurrentDictionary<long, string> condic = new Concurre ...

  4. C#打印杨辉三角

    重主要的方法在于: 1.初始化二维数组 2.边界赋值 3.中心值赋值 4.输出 <pre name="code" class="csharp"> c ...

  5. fastq,sam文件一些小结(持续补充。。。)

    ST-E00211::H5L3NCCXY:::: chr14 141M = - ACTTCACCTCCTGGAGTCCTGGACTTCCCCACATCTCCCCTGCCCCTCCCACGTTTCCAT ...

  6. C# 使用 CancellationTokenSource 终止线程

    http://blog.csdn.net/hezheqiang/article/details/51966511 我们在多线程中通常使用一个 C# 使用 CancellationTokenSource ...

  7. jQuery的get()post()getJson()方法

    jQuery get() 和 post() 方法用于通过 HTTP GET 或 POST 请求从服务器请求数据. HTTP 请求:GET vs. POST 两种在客户端和服务器端进行请求-响应的常用方 ...

  8. MicroPython-TPYBoard固件编译教程

    本文主要介绍一下,在Linux环境下编译micropython固件的方法和流程. 首先,我们先来看一下MicroPython的源码结构. github地址:https://github.com/mic ...

  9. Java 读取配置文件

    1.读取XML文件使用dom4j-full.jar包的SAXReader解析: Document document=new SAXReader.reader("xml文路径/文件名xxx.x ...

  10. css3实现图片旋转效果

    css3实现图片旋转效果 近期实现一个消息提醒(醒目)的需求页面.想到了css3的旋转动画,故使用. =============== 鼠标悬浮时候,图片可以旋转,放大 rotate(360deg) s ...