Evacuation,题解
题目:



题意:
有人,门(只有边上有,且1s只能出去一个人),和墙,每s人可移动一个格子,问多少秒所有人可以逃出,逃不出输出“impossible”
分析:
首先,我们先想着样一个问题,如果这个人在某一秒可以到达了这个们,他将可以在这1s之后的任一没人通过此门的时刻出门。而且题意说每个门每一刻只能使1人通过,那么我们可以直接把门分成好多门(1s一个,当然时间有上线),然后让人和这些门去匹配就好了,看一下第几秒可以人都匹配上就好了,当然我们加一个二分不要一个一个跑了,最后复杂度:10(二分)*10*10(人)*10*10(人)*44(门)*100(时间)(有些估算的较大),有点大,不过还是可以的,毕竟这样求匹配的常熟是很小的。当然有人写的是用D去匹配.然后不用二分了,但是这样的复杂度更大了,它是10*10(人)*44(门)*100(时间)*44(门)*100(时间),而且常数可能也大了。最后就是代码。
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
char ch[][];
const int maxn=***+;
struct E{
int to;
int next;
int val;
}ed[maxn];
int head[maxn],ma[maxn],tot;
bool vis[][];
void J(int a,int b,int c){
ed[++tot].to=b;
ed[tot].val=c;
ed[tot].next=head[a];
head[a]=tot;
}
struct Node{
int x,y,t;
Node(){}
Node(int a,int b,int c){x=a;y=b;t=c;}
};
int x,y;
queue<Node> qu;
int dx[]={,,,-};
int dy[]={,-,,};
int M1(int a,int b){return y*(a-)+b;}
int M2(int a,int b,int t){return (M1(a,b)-)*+t;}
void JIA(int a,int b,int nx,int ny,int t){
for(int i=t;i<=;i++)
J(M1(a,b),M2(nx,ny,i),i);
}
void Bfs(int a,int b){
memset(vis,,sizeof(vis));
vis[a][b]=;
qu.push(Node(a,b,));
while(!qu.empty()){
Node js=qu.front();
qu.pop();
for(int i=;i<;i++){
int nx=js.x+dx[i],ny=js.y+dy[i];
if(nx>=&&nx<=x&&ny>=&&ny<=y&&!vis[nx][ny]&&ch[nx][ny]=='.'){
vis[nx][ny]=;
qu.push(Node(nx,ny,js.t+));
}
if(nx>=&&nx<=x&&ny>=&&ny<=y&&!vis[nx][ny]&&ch[nx][ny]=='D'){
vis[nx][ny]=;
JIA(a,b,nx,ny,js.t+);
}
}
}
}
bool vis2[maxn];
bool Dfs(int x,int t){
for(int i=head[x];i;i=ed[i].next){
if(vis2[ed[i].to]||ed[i].val>t) continue;
vis2[ed[i].to]=;
if(ma[ed[i].to]==||Dfs(ma[ed[i].to],t)){ma[ed[i].to]=x;return ;}
}
return ;
}
bool pd(int t){
memset(ma,,sizeof(ma));
for(int i=;i<=x;i++)
for(int j=;j<=y;j++)
if(ch[i][j]=='.'){
memset(vis2,,sizeof(vis2));
if(!Dfs(M1(i,j),t)) return ;
}
return ;
}
int main(){
int t;
scanf("%d",&t);
for(int jsjs=;jsjs<=t;jsjs++){
scanf("%d%d",&x,&y);
memset(head,,sizeof(head));
tot=;
for(int i=;i<=x;i++) for(int j=;j<=y;j++) scanf(" %c",&ch[i][j]);
for(int i=;i<=x;i++) for(int j=;j<=y;j++) if(ch[i][j]=='.') Bfs(i,j);
int l=,r=;
while(l<=r){
int mid=(l+r)/;
if(pd(mid)) r=mid-;
else l=mid+;
}
if(l==) printf("impossible\n");
else printf("%d\n",l);
}
return ;
}
Evacuation,题解的更多相关文章
- POJ 3057 Evacuation 题解
题目 Fires can be disastrous, especially when a fire breaks out in a room that is completely filled wi ...
- Emergency Evacuation 题解
The Japanese government plans to increase the number of inbound tourists to forty million in the yea ...
- POJ3057:Evacuation——题解
http://poj.org/problem?id=3057 题目大意: .为人,D为门,X为障碍,门每秒只能出去一个人,问多少秒出光. 如果无法出光输出impossible. ——————————— ...
- Emergency Evacuation,题解
题目: 题意: 在某一秒,每个人可以进行一个移动:去旁边座位,去过道,在过道向出口走,求最少多少秒可以让所有人离开(具体如图和样例). 分析: 首先,我们先考虑简单的,只考虑出口前有什么事件发生:1. ...
- Codeforces Gym 100002 E "Evacuation Plan" 费用流
"Evacuation Plan" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- POJ 3057 Evacuation 二分+最大流
Evacuation 题目连接: http://poj.org/problem?id=3057 Description Fires can be disastrous, especially when ...
- POJ2175:Evacuation Plan(消负圈)
Evacuation Plan Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5665Accepted: 1481Special J ...
- ICPC — International Collegiate Programming Contest Asia Regional Contest, Yokohama, 2018–12–09 题解
目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
随机推荐
- sql server 连接种类
一.连接种类 内连接 inner join 如果分步骤理解的话,内连接可以看做先对两个表进行了交叉连接后,再通过加上限制条件(SQL中通过关键字on)剔除不符合条件的行的子集,得到的结果就是内连接了. ...
- npm run dev启动项目,electron提示throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
npm run dev 项目,提示 throw new Error('Electron failed to install correctly, please delete node_modules/ ...
- 00-04.kaliLinux-手动配置IP地址
在KaliLinux中手动配置网卡 用vim打开网卡的配置文件,配置各个网卡信息 root@kali:~# cd /etc/network root@kali:/etc/network# ------ ...
- Debian安装NVIDIA显卡驱动
1. sudo apt-get install nvidia-detect nvidia-detect 输出信息: Detected NVIDIA GPUs: 01:00.0 VGA compatib ...
- 如何在Centos7安装swoole的PHP扩展
1. 下载swoole源代码包 wget -c https://github.com/swoole/swoole-src/archive/v2.0.8.tar.gz 2.tar -zxvf v2.0. ...
- [CF453D]Little Pony and Elements of Harmony
题目 点这里看题目. 分析 设\(count(x)\)为\(x\)的二进制中\(1\)的个数.因此\(f(u,v)=count(u\oplus v)\) 看一看每次转移,我们发现最不友好的 ...
- node-sass问题
cnpm install node-sass@latest 或者 所以用npm install -g cnpm --registry=https://registry.npm.taobao.org , ...
- Happens-Before原则
Java内存模型是通过各种操作来定义的,包括对变量的读/写操作,监视器的加锁和释放操作,以及线程的启动和合并操作.JMM为程序中所有的操作定义了一个偏序关系,称之为Happens-Before.要想保 ...
- PIP设置镜像源
PIP设置镜像源 pip安装Python包时候,默认是国外的下载源,速度太慢,本文介绍几种设置pip国内镜像源的方法 镜像源 阿里云 http://mirrors.aliyun.com/pypi/si ...
- python的坑--你知道吗?
python的坑--你知道吗? 1.列表的坑 坑的地方是:因为列表用pop之后,后面的索引都会自动减一 # 列表的坑之一 list1 = ['python','java','php','c','c++ ...