题目链接

One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are NNN spots in the jail and MMM roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K−1)(K-1)(K−1)-th shortest path. If Pucci spots JOJO in one of these K−1K-1K−1 routes, Pucci will use his stand Whitesnake and put the disk into JOJO's body, which means JOJO won't be able to make it to the destination. So, JOJO needs to take the KKK-th quickest path to get to the destination. What's more, JOJO only has TTT units of time, so she needs to hurry.

JOJO starts from spot SSS, and the destination is numbered EEE. It is possible that JOJO's path contains any spot more than one time. Please tell JOJO whether she can make arrive at the destination using no more than TTT units of time.

Input

There are at most 505050 test cases.

The first line contains two integers NNN and MMM (1≤N≤1000,0≤M≤10000)(1 \leq N \leq 1000, 0 \leq M \leq 10000)(1≤N≤1000,0≤M≤10000). Stations are numbered from 111 to NNN.

The second line contains four numbers S,E,KS, E, KS,E,K and TTT ( 1≤S,E≤N1 \leq S,E \leq N1≤S,E≤N, S≠ES \neq ES≠E, 1≤K≤100001 \leq K \leq 100001≤K≤10000, 1≤T≤1000000001 \leq T \leq 1000000001≤T≤100000000 ).

Then MMM lines follows, each line containing three numbers U,VU, VU,V and WWW (1≤U,V≤N,1≤W≤1000)(1 \leq U,V \leq N, 1 \leq W \leq 1000)(1≤U,V≤N,1≤W≤1000) . It shows that there is a directed road from UUU-th spot to VVV-th spot with time WWW.

It is guaranteed that for any two spots there will be only one directed road from spot AAA to spot BBB (1≤A,B≤N,A≠B)(1 \leq A,B \leq N, A \neq B)(1≤A,B≤N,A≠B), but it is possible that both directed road <A,B><A,B><A,B> and directed road <B,A><B,A><B,A> exist.

All the test cases are generated randomly.

Output

One line containing a sentence. If it is possible for JOJO to arrive at the destination in time, output "yareyaredawa" (without quote), else output "Whitesnake!" (without quote).

样例输入复制

2 2
1 2 2 14
1 2 5
2 1 4

样例输出复制

yareyaredawa

先说说A*算法;

我也是初学者,对A*算法懂得不多,看了许多别人的博客,他们写的都很透彻,同时也很专业,

我就用不专业的话说说我对A*算法的理解;

大佬请略过。。。。。。。。。。。。

A*算法重要的应该是它能起到一个预知的效果,看别人的博客都知道一个函数F=G+H;而他的最重要的在于H函数;

H函数的作用是用来判断这个点到终点的距离,就像图中的H和G,g记录了你走过的距离,h记录着当前的到终点你还要走的距离,一半H需要自己通过计算得到,如本题的H就是可以由终点计算到其他点的距离得到每一个点到终点的距离,所以H函数写的好的程序就好,而对于当前的该怎样走才是最短的,就需要比较它周围的点的G加上H的值,值越小,到终点的距离越大。有时候H很难算出这时就可以用一些特殊的方式求H值比如直接取两点距离,但是H需要<=实际的值,如果估计的比实际的大,那估计也很难的出正确结果,(反正我是不知道,我是一个很菜的人);求H的距离很重要,这或许就是别人博客中说H重要,关系到算法好坏的一个点了。。。。。。

有了H,G就只需要记录就行了,走一步记一步,f主要是运用在选择上。

我的A*算法只能给刚开始学的人一个小小的理解,同时也是让我自己能更加理解这道题才写的这篇博客。。。。。

代码

#include <iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std;
#define N 10005
typedef pair<int,int> P;
vector<P>vs[N],rvs[N];
int s,e,k,t;
int dist[N];//记录H
struct Node
{int v;//当前点int g;int f;bool operator <(const Node &a)const{return f>a.f;//用来比较F大小}
};
void dij(int e)//这个函数用来求H
{priority_queue<P, vector<P>, greater<P> >que;que.push(P(0,e));memset(dist,0x3f3f3f3f,sizeof(dist));dist[e]=0;while(que.size()){P t=que.top();que.pop();for(int it=0; it<(int)rvs[t.second].size(); it++){int v=rvs[t.second][it].first;int w=rvs[t.second][it].second;if(dist[v]>w+dist[t.second]){dist[v]=w+dist[t.second];que.push(P(dist[v],v));}}}
}int sove(int s)//这个函数用来判断怎么走
{priority_queue<Node>que;//用队列que.push((Node){s,0,0});int ans=0;while(que.size()){Node t=que.top();que.pop();if(t.v==e)ans++;//到终点的次数if(ans==k)return t.g;for(int i=0; i<(int)vs[t.v].size(); i++){int v=vs[t.v][i].first;int w=vs[t.v][i].second;Node p;p.v=v;p.g=t.g+w;//G的值p.f=p.g+dist[v];//F的值que.push(p);}}return 0;
}
int main()
{int n,m;while(scanf("%d %d",&n,&m)!=EOF){scanf("%d %d %d %d",&s,&e,&k,&t);for(int i=1; i<=n; i++)vs[i].clear(),rvs[i].clear();for(int i=1; i<=m; i++){int a,b,v;scanf("%d %d %d",&a,&b,&v);vs[a].push_back(P(b,v));rvs[b].push_back(P(a,v));}dij(e);if(dist[s]==0x3f3f3f3f)//如果没有通路{cout<<"Whitesnake!\n";continue;}int sum=sove(s);if(sum>t)//时间是否在t内{cout<<"Whitesnake!\n";}else{cout<<"yareyaredawa\n";}}return 0;
}

Made In Heaven(A*算法初步学习)相关推荐

  1. java五子棋的重要算法讲解_[Java五子棋小游戏-Ai算法精讲以及实现]-02--高级算法初步...

    高级算法初步 走对自己利益最大的路 它有难了不要慌,抛弃它,以这盘棋局的胜利为他报仇 碰撞检测与跨步算法原理图 反向计算权重 每次计算完权重,都要进行一次反向权重计算 权重值 : 两侧的权重值相加 权 ...

  2. 推荐算法工程师学习路线及工作指南

    干货!推荐算法工程师学习路线及工作指南 以下文章来源于大数据与人工智能 ,作者gongyouliu 本文从我自己的学习成长经历.如何判断自己是否适合从事推荐算法.推荐算法工程师需要的知识储备.怎么找一 ...

  3. 算法初步 计算机程序,算法初步-程序框图

    算法初步-程序框图 (10页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 9.9 积分 1. 1. 2程序槌0B簿二.三课町一. 教学目标:1. 知识与技 ...

  4. 高中数学必修3知识点总结归纳:第一章算法初步

    大家好,今天分享高中数学必修3知识点总结归纳第一章算法初步,也是高中数学教学的重要内容.老师为大家整理的高中数学必修3算法初步知识点总结归纳,一起来看看吧. 好了,今天高中数学必修3知识点总结归纳第一 ...

  5. 学习点云和pcl算法初步②

    ** 点云初步学习② 主要工具:visual studio 2019 和cloudcompare(自行编译) 1.点云预处理(滤波):①点云去噪②点云的简化 原因: (1) 点云数据密度不规则需要平滑 ...

  6. 算法初步--二分法(以PAT考试A1010为例题)

    算法初步--二分法 二分法的经典问题 经典问题的微扩展 经典问题的总结 PAT考试真题A1010.Radix 后记 二分法的经典问题 从一个经典问题开始:给定一个严格递增序列,要求找到当中的某个元素所 ...

  7. HTMLParser的初步学习

    Python的自带模块--HTMLParser的初步学习 HTMLParser是Python自带的模块,使用简单,能够很容易的实现HTML文件的分析. 本文主要简单讲一下HTMLParser的用法. ...

  8. 初步学习pg_control文件之三

    接前文,初步学习pg_control文件之二 继续学习: 研究 DBState,先研究 DB_IN_PRODUCTION ,看它如何出现: 它出现在启动Postmaster时运行的函数处: /* * ...

  9. eclipsevue代码怎么运行_[Java教程]使用eclipse初步学习vue.js操作

    [Java教程]使用eclipse初步学习vue.js操作 0 2017-11-26 19:00:06 一.vue.js的初步认识 https://unpkg.com/vue ">vu ...

  10. json2.js的初步学习与了解(转)

    转载来源:http://apps.hi.baidu.com/share/detail/6092406 json2.js的初步学习与了解 1.)该js的下载地址是:http://www.json.org ...

最新文章

  1. C#中的Liststring泛型类示例
  2. REPL (read-evaluate-print-loop)概念-读取评估打印循环
  3. Python数据可视化实战应用万字长文从入门到高端(建议收藏)
  4. Flink从入门到精通100篇(二十三)-基于Apache Flink的爱奇艺实时计算平台建设实践
  5. html 一个圆圈一个c,如何用c语言程序画一个圆?
  6. 《零基础看得懂的C++入门教程 》——(9)结构体原来如此
  7. php如何解决脏读,php 技术沉淀
  8. python集群到hadoop_如何使用Hadoop流在本地Hadoop集群中运行MRJob?
  9. Chrome浏览器导出插件crx
  10. 数据结构:二叉搜索树(BST)全部基本操作
  11. 由一次NoHttpResponseException异常,追究到Http长连接和短连接
  12. html调用eps,eps输出没有属性
  13. Linux安装log4cpp
  14. 【AD封装】电感(带3D)
  15. linux系统添加网卡驱动,linux添加网卡及驱动
  16. centos 关机命令_全了 Linux 常用命令大汇集
  17. shell 中三种引号的用法及区别
  18. 自学Java的心路历程
  19. QT5.6 安装 过程,实践经历……
  20. 贪吃蛇c语言程序复杂,刚学C语言,想写一个贪吃蛇的代码

热门文章

  1. 三星 Android6,三星公布第二批更新安卓9.0系统,六款机型中有没有你用的机型?...
  2. pygame自学飞机大战
  3. 数学建模常用模型08 :主成分分析
  4. Best Practices for Power Manageable Device Drivers
  5. C++ | 一些你所忽略的类和对象小知识
  6. GPLv3协议中文翻译
  7. 外卖小哥帮程序员写代码,走红网络!除此之外,还有他!
  8. WEB-CTF 条件竞争
  9. 数学建模Day1 层次分析法
  10. 阿里巴巴2016研发工程师笔试题(四)