坑啊。。

  膜了半天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. mongodb 复制集

    mongodb 复制集 复制集简介 Mongodb复制集由一组Mongod实例(进程)组成,包含一个Primary节点和多个Secondary节点,Mongodb Driver(客户端)的所有数据都写 ...

  2. Function:html结构转字符串形式显示

    //Html结构转字符串形式显示 支持<br>换行 function ToHtmlString(htmlStr) { return toTXT(htmlStr).replace(/\&am ...

  3. Java.util.Map排序输出

    在java的众多Map实现中,Map基本上是不能保证顺序的(LinkedHashMap可以保证插入顺序或者访问顺序,TreeMap默认按照key升序但可以自定义Comparator),在开发过程中当数 ...

  4. 10本Java书籍推荐

    1. <深入理解Java虚拟机>是近年来国内出版的唯一一本与Java虚拟机相关的专著,也是唯一一本同时从核心理论和实际运用这两个角度去探讨Java虚拟机的著作,不仅理论分析得透彻,而且书中 ...

  5. bzoj 4719: [Noip2016]天天爱跑步

    Description 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要 玩家每天按时上线,完成打卡任务.这个游戏的地图可以看作一一 ...

  6. lesson - 10 课程笔记

    CTRL+C CTRL+D :前者用于结束一个程序,后者用于结束终端输入. --符号 *:匹配任意长度的任意字符 ?:匹配任意一个字符 #: shell 中表注释 \: 脱意符号 []:任意属于字符组 ...

  7. Linux第五节随笔 /file / vim / suid /sgid sbit

    三期第四讲1.查询文件类型与文件位置命令 file 作用:查看文件类型(linux下的文件类型不以后缀名区分) 语法举例: [root@web01 ~]# file passwd passwd: AS ...

  8. 高仿二次元网易GACHA

    高仿二次元网易GACHA,所有接口均通过Charles抓取而来,图片资源通过 https://github.com/yuedong56/Assets.carTool 工具提取. 详情见github地址 ...

  9. datatable使用笔记

    这是一个使用datatable的jsp文件实例,实现了点击单元格后编辑单元格所在行的内容. <%@ page pageEncoding="UTF-8"%> <!D ...

  10. React日常填坑手册(持续更新)

    1.react中自己定义的组件第一个字母一定要大写,如<app />会不显示,<App />才能正常显示. 2.在react中点击事件里面setState时会使this重新定义 ...