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*算法)相关推荐

  1. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven (K短路算法模板)

    题意 : 求第k短路的权值是否超过T(权值) 解法: 网上随便找的一个求K短路的算法模板套弄一下即可 (模板要好,不然邻接表存图会TLE , 网上换了两个模板才AC的) AC代码: #include& ...

  2. 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 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 Spare Tire(容斥+公式推)

    A sequence of integer \lbrace a_n \rbrace{an​} can be expressed as: \displaystyle a_n = \left\{ \beg ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)

    关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...

  5. 【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice's basics in digital electronics

    [链接] 我是链接,点我呀:) [题意] [题解] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [代码] #include <bits/stdc+ ...

  6. 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 ...

  7. ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang 分块

    https://nanti.jisuanke.com/t/31451 对每层的个数分块 当这个深度的节点个数>block时 暴力维护每个点的子树有多少个这个深度的节点 这样的层数最多有n/blo ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang(树分块)

    思路 因为不同深度的节点数量不同,数量少的节点,可以考虑直接进行单点更新,对于数量多的节点,可以直接记录这一层增加的值,查询的时候,看每一层有多少个节点,最后乘上增加的值就行了. 具体实现 先设定一个 ...

  9. 【ACM-ICPC 2018 沈阳赛区网络预赛】I.Lattice's basics in digital electronics ---- 字典树

    题目传送门 做法: 用字典树存好译码词,然后模拟即可 AC代码: #include <bits/stdc++.h> using namespace std;#define IO ios_b ...

最新文章

  1. CORS漏洞利用检测和利用方式
  2. 使用OpenCV搭建违章停车检测系统
  3. 手机不断进入recovery mode
  4. IP地址配置冲突导致路由振荡怎么办
  5. Java接口回调机制
  6. 这几个关乎我们一生教养的原则,每个人都应该知道。
  7. centos6.5 python2.6.6升级到python2.7.15
  8. Faster RCNN好文(转)
  9. 中英文对照 —— 图表等的可视化
  10. Android输入法
  11. 冲突域和CSMA/CD
  12. Android HAL
  13. java随机数Reandom(简单介绍)
  14. 基因表达式编程的任务指派问题求解算法设计与实现
  15. 云主机管理系统源码php,云优CMS PHP企业网站管理系统(分站版) v2.0.8
  16. 请问在深圳做美工的工资多少
  17. 实战案例|拒绝信息泄露,腾讯云助力电商对抗网络爬虫
  18. c语言编写开关程序,C语言开关语句:switch
  19. 通过api获取网易云音乐歌单数据
  20. 这可能是2021年GDPR的最大罚单

热门文章

  1. php多进程有什么用,有关php多进程的用法举例
  2. python cpython关系_第3篇:CPython内部探究:PyASCIIObject的初始化
  3. abaqus的python安装文件在哪_在abaqus2016中安装xlwt和xlrd库教程
  4. c语言函数 t啥意思,C语言函数大全(t开头)
  5. matlab中fir1中的边界频率,FIR滤波器的MATLAB设计与实现.pdf
  6. vst3插件_2B Played Music发布用于劲爆舞曲风格的极端失真和剪辑插件2B Clipped XT
  7. java hashmap扩容大小_HashMap的扩容机制以及默认大小为何是2次幂
  8. python 字符串去重且相同字符最多出现2次_Python实现计算字符串中出现次数最多的字符示例...
  9. html所有页面根的对象,在django中显示来自所有用户的对象,无需登录到html页面...
  10. 字节跳动 java面经_字节跳动Java面经(已offer)