ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)
https://nanti.jisuanke.com/t/31445
题意
能否在t时间内把第k短路走完。
分析
A*算法板子。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <cmath> #include <ctime> #include <vector> #include <queue> #include <map> #include <stack> #include <set> #include <bitset> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ms(a, b) memset(a, b, sizeof(a)) #define pb push_back #define mp make_pair #define pii pair<int, int> #define eps 0.0000000001 #define IOS ios::sync_with_stdio(0);cin.tie(0); #define random(a, b) rand()*rand()%(b-a+1)+a #define pi acos(-1) //const ll INF = 0x3f3f3f3f3f3f3f3fll; const int inf = 1e9; const int maxn = 1000 + 10; const int maxm = 100000 + 10; const int mod = 1000000007; int head[maxn],nxt[maxm],head1[maxn],nxt1[maxm]; int dis[maxn]; bool vis[maxn]; int n,m,e,st,en,k,t; struct note{int u,v,c;note(){}note(int u,int v,int c):u(u),v(v),c(c){} }p[maxm]; struct POJ{int v,c;POJ(){}POJ(int v,int c):v(v),c(c){}bool operator < (const POJ& other)const{return c+dis[v]>other.c+dis[other.v];} }; void addnote(int u,int v,int c){p[e]=note(u,v,c);nxt[e]=head[u];head[u]=e;nxt1[e]=head1[v];head1[v]=e++; } void dij(int src){memset(vis,0,sizeof(vis));for(int i=1;i<=n;i++) dis[i]=inf;dis[src]=0;priority_queue<POJ> que;que.push(POJ(src,0));while(!que.empty()){POJ pre=que.top();que.pop();vis[pre.v]=true;for(int i=head1[pre.v];i+1;i=nxt1[i]){if(dis[p[i].u]>dis[pre.v]+p[i].c){dis[p[i].u]=dis[pre.v]+p[i].c;que.push(POJ(p[i].u,0));}}while(!que.empty()&&vis[que.top().v]) que.pop();} } int a_star(int src){priority_queue<POJ> que;que.push(POJ(src,0));k--;while(!que.empty()){POJ pre=que.top();que.pop();if(pre.v==en){if(k) k--;else return pre.c;}for(int i=head[pre.v];i+1;i=nxt[i])if(pre.c+p[i].c<=t)que.push(POJ(p[i].v,pre.c+p[i].c));}return -1; } int main(){ #ifdef LOCALfreopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endifwhile(~scanf("%d%d",&n,&m)){scanf("%d%d%d%d",&st,&en,&k,&t);memset(head,-1,sizeof(head));memset(head1,-1,sizeof(head1));e=0;for(int i=0;i<m;i++){int u,v,c;scanf("%d%d%d",&u,&v,&c);addnote(u,v,c);}dij(en);if(dis[st]==inf){puts("Whitesnake!");continue;} // if(st==en) k++;int ans=a_star(st);if(ans==-1||ans>t){puts("Whitesnake!");}else{puts("yareyaredawa");} // printf("%d\n",a_star(st)); }return 0; }
转载于:https://www.cnblogs.com/fht-litost/p/9671523.html
ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)相关推荐
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven (K短路算法模板)
题意 : 求第k短路的权值是否超过T(权值) 解法: 网上随便找的一个求K短路的算法模板套弄一下即可 (模板要好,不然邻接表存图会TLE , 网上换了两个模板才AC的) AC代码: #include& ...
- ACM-ICPC 2018 沈阳赛区网络预赛(E F G J K)
ACM-ICPC 2018 沈阳赛区网络预赛(E F G J K) 复杂的模拟题懒癌患者表示写不动 D. Made In Heaven (K短路) 略 int head[MAXN]; int cure ...
- ACM-ICPC 2018 沈阳赛区网络预赛 Spare Tire(容斥+公式推)
A sequence of integer \lbrace a_n \rbrace{an} can be expressed as: \displaystyle a_n = \left\{ \beg ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)
关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...
- 【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice's basics in digital electronics
[链接] 我是链接,点我呀:) [题意] [题解] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [代码] #include <bits/stdc+ ...
- Convex Hull (ACM-ICPC 2018 沈阳赛区网络预赛) 存个公式
Convex Hull gay(i)={0ifi=k×x×x,x>k,k>1i×ielse}求∑i=1n∑j=1igay(j)=∑i=1n(n−i+1)gay(i)=∑i=1n(n−i+1 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang 分块
https://nanti.jisuanke.com/t/31451 对每层的个数分块 当这个深度的节点个数>block时 暴力维护每个点的子树有多少个这个深度的节点 这样的层数最多有n/blo ...
- ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang(树分块)
思路 因为不同深度的节点数量不同,数量少的节点,可以考虑直接进行单点更新,对于数量多的节点,可以直接记录这一层增加的值,查询的时候,看每一层有多少个节点,最后乘上增加的值就行了. 具体实现 先设定一个 ...
- 【ACM-ICPC 2018 沈阳赛区网络预赛】I.Lattice's basics in digital electronics ---- 字典树
题目传送门 做法: 用字典树存好译码词,然后模拟即可 AC代码: #include <bits/stdc++.h> using namespace std;#define IO ios_b ...
最新文章
- 卷积神经网络通俗解读
- 印象系列-磁盘和内存的基本认识
- Flex 容器基本概念
- 使用 golang 调用consul api 接口,注册user-tomcat服务
- Android --- 夜神模拟器中没有图片怎么办?夜神模拟器中怎么导入图片?
- 机器学习 聚类篇——python实现DBSCAN(基于密度的聚类方法)
- java面试题-精心准备
- hybris impex里的多语言处理语法
- firefox input file宽度失效
- 第三次个人赛题目2 【多项式输出格式】
- jQuery - 链(Chaining)
- 无忧PHP企业网站内容管理系统源码v2.8 标准版
- php 数据映射,数据映射模式(Data Mapper)
- Bootstrap页面布局18 - BS导航路径以及分页器
- C++ 11中几个我比较喜欢的语法
- 如何在互联网上寻找免费电子书?(其二)
- linux配置tp路由器,手把手图解教程tplink r402m路由器配置
- 关于我从有转行的想法到下定决心转行的经历
- android来电没有弹窗
- 7-62 贴“福”字
热门文章
- 模拟inode号耗尽、EXT和XFS类型文件恢复(详细图解)
- c语言版票务管理系统,火车票务管理系统(C语言版)【TXT文件,改后缀即可】
- Windows Server 笔记之磁盘管理
- RedHat虚拟机Vmware Tools的安装教程
- 什么是java序列化,如何实现java序列化?
- 如何把a1的图纸变成a0_如何安装家用空开配电
- linux打包压缩命令有哪些,Linux压缩打包命令使用方法有哪些呢?
- 如何利用python在yi'ge_【GE查找Python面试题】面试问题:使用 TVM … - 看准网
- vbmsgbox引用变量_vba中MsgBox的参数及用法
- java文件客户端下载_使用Java写一个minio的客户端上传下载文件