P3393 逃离僵尸岛

啊。好久不写dij手都生了

这道题就是预先处理出是否是危险城市,然后跑一个最短路就行了

然后因为我感觉这个对时间要求不大紧。判断危险城市时就写了个电风扇(DFS)

然后T飞了呜呜呜~~

//Dan数组是标记一个城市是否是危险城市
void danger(int now,int dist)
{
if(dist>s) return ;
if(!Dan[now]) Dan[now]=1;
if(!dist) Dan[now]=-1;//-1表示感染城市
for(int i=head[now];i;i=line[i].nxt)
danger(line[i].p,dist+1);
}

然后又怒改了一波百分数(BFS)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using std::swap;
using std::queue;
const int N=101000,M=202000;
struct Data
{
int p;
long long dis;
bool operator < (const Data &a)const
{
return dis<a.dis;
}
};
struct Link
{
int p;
int nxt;
};
Data base[M<<3];
Link line[M<<1];
int head[N],tail;
int n,m,k,s,p,q,len;
int zombie[N];
int Dan[N];
long long dis[N];
bool get[N];
Data top()
{
return base[1];
}
void push(Data a)
{
base[++len]=a;
int pos=len;
while((pos>>1)&&base[pos]<base[pos>>1])
{
swap(base[pos],base[pos>>1]);
pos>>=1;
}
return ;
}
void pop()
{
swap(base[1],base[len--]);
int pos=1,nxt;
while(true)
{
nxt=pos;
if(base[pos<<1]<base[nxt]&&(pos<<1)<=len)
nxt=pos<<1;
if(base[pos<<1|1]<base[nxt]&&(pos<<1|1)<=len)
nxt=pos<<1|1;
if(pos==nxt) break;
swap(base[pos],base[nxt]);
pos=nxt;
}
return ;
}
void add(int a,int b)
{
line[++tail].p=b;
line[tail].nxt=head[a];
head[a]=tail;
}
queue<int>Q;
void danger()
{
while(!Q.empty())
{
int pas=Q.front();Q.pop();
for(int i=head[pas];i;i=line[i].nxt)
if(!Dan[line[i].p]&&Dan[pas]<s)
{
Dan[line[i].p]=Dan[pas]+1;
Q.push(line[i].p);
}
}
for(int i=1;i<=k;i++) Dan[zombie[i]]=-1;
}
int main()
{
memset(dis,127,sizeof(dis));
scanf("%d%d%d%d%d%d",&n,&m,&k,&s,&p,&q);
for(int i=1;i<=k;i++)
{
scanf("%d",&zombie[i]);
Q.push(zombie[i]);
}
int a,b;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
add(a,b);add(b,a);
}
danger();
Data pas,nxt;pas.p=1;pas.dis=0;
push(pas);
while(len)
{
pas=top();
while(get[pas.p]){ pop();pas=top(); }
get[pas.p]=true;dis[pas.p]=pas.dis;
if(pas.p==n) break;
for(int i=head[pas.p];i;i=line[i].nxt)
{
int v=line[i].p;
long long dist=p;
if(Dan[v]==-1) continue;
if(Dan[v]) dist=q;
if(v==n) dist=0;
if(dis[pas.p]+dist<dis[v])
{
nxt.p=v;
nxt.dis=dis[v]=dis[pas.p]+dist;
push(nxt);
}
}
}
printf("%lld",dis[n]);
}

P3393 逃离僵尸岛的更多相关文章

  1. luogu P3393 逃离僵尸岛-搜索剪枝+spfa

    P3393 逃离僵尸岛 题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被 ...

  2. luogu P3393 逃离僵尸岛

    luoguP3393逃离_僵尸岛_ 一道洛谷不知道哪门子月赛的题 可以用此题来练习最短路算法 SPFA和dijkstra的练习题(关于Floyed,他死了 思路: 本题是最短路板子. 首先就是建立虚点 ...

  3. 洛谷⑨月月赛Round2 P3393逃离僵尸岛[最短路]

    题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...

  4. 洛谷P3393 逃离僵尸岛

    题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...

  5. 【luogu P3393 逃离僵尸岛】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3393 被占领的点可以先连在一个点上然后只需要对这一个点bfs一遍就可以求所有的危险点 #include &l ...

  6. 洛谷P3393逃离僵尸岛 最短路

    貌似一直不写题解不太好QAQ 但是找不到题啊... 随便写点水题来补博客吧 题目不pa了,点链接吧... 点我看题 很明显这是道sb题... 思路:  对于每一个僵尸城市预处理其 s 距离内的城市,然 ...

  7. 洛谷 P3393 逃离僵尸岛

    洛谷 这道题目其实是最短路裸题. 首先看到题目,要求的到"被占点"距离不大于S的点,自然想到了以"被占点"为源点,求一遍最短路,处理出"危险点&quo ...

  8. Luogu P3393 逃离僵尸岛【最短路】By cellur925

    题目传送门 题目大意:(其实概括出来也就基本做完了hh)在一张有$n$个点,$m$条边的无向图上,有$k$个点是不能经过的,而与之距离不超过$s$的点,到他们会花费$Q$元,到其他点会花费$p$元,求 ...

  9. [题解] 洛谷 P3393 逃离僵尸岛

    题目TP门 很明显是一个最短路,但是如何建图才是关键. 对于每一个不可遍历到的点,可以向外扩散,找到危险城市. 若是对于每一个这样的城市进行搜索,时间复杂度就为\(O(n^2)\),显然过不了.不妨把 ...

随机推荐

  1. (转)PEP 8——Python编码风格指南

    PEP 8——Python编码风格指南标签(空格分隔): Python PEP8 编码规范原文:https://lizhe2004.gitbooks.io/code-style-guideline-c ...

  2. bootstrap框架的使用

    1.默认修改input输入框激活的颜色(充电桩) .form-control:focus, .ms-choice:focus, input[type=text]:focus, input[type=p ...

  3. 清除浮动clear-left-right-both-none效果

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. nginx location 配置阐述优先级别使用说明

    使用nginx 有大半年了,它的高性能,稳定性表现很好. 这里也得到很多人的认可. 其中它的配置,有点像写程序一样,每行命令结尾一个";"号,语句块用"{}"括 ...

  5. IBM Rational Appscan: Part 2 ---reference

    http://resources.infosecinstitute.com/appscan-part-2/ By Rohit T|August 16th, 2012 ----------------- ...

  6. Linux下Makefile的automake生成全攻略--转

    http://www.yesky.com/120/1865620.shtml 作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下 ...

  7. 通过js控制层的动态隐藏

    <style type="text/css"> #dv1{ width:1000px; height:1000px; overflow:hidden; display: ...

  8. Java 访问权限控制- protected 关键字

    protected 关键字的真正内涵 文章来源:http://blog.csdn.net/justloveyou_/article/details/61672133 很多介绍Java语言的书籍(包括& ...

  9. Spring课程 Spring入门篇 4-4 Spring bean装配(下)之Autowired注解说明3 多选一 qualifier

    本节主要讲述以下内容: 1 简述 2 代码演练 2.1 注解qualifier运用 1 简述 1.1 何种情况使用qualifier注解? a 按类型自动装配多个bean实例,可以用@qualifie ...

  10. HTML字符实体名称/实体编号

    字符实体对英文的大小写敏感! 字符实体一: 显示结果 描述 实体名称 实体编号   空格     < 小于号 < < > 大于号 > > & 和号 & ...