题意是让求从st的ed第k短路。。。

考虑A*算法:先把终点到每个点最短路跑出来(注意要建反图),当做估价函数h(u),然后跑A*

每次取出总代价最小的,即g(u)+h(u)最小的进行扩展,注意如果u被取出的次数c[u]>k,就不再进行扩展了。

当ed被取出且c[ed]==k,那么答案就是此时的g(ed)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define R register int
#define mp make_pair
const int Inf=0x3f3f3f3f,M=,N=;
using namespace std;
inline int g() {
R ret=; register char ch; while(!isdigit(ch=getchar())) ;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret;
}
int n,m,cnt,ccnt,st,ed,k;
int vr[M],w[M],nxt[M],fir[N];
int vv[M],ww[M],nn[M],ff[N],d[N],c[N];
bool vis[N];
inline void add(int u,int v,int ww) {vr[++cnt]=v,w[cnt]=ww,nxt[cnt]=fir[u],fir[u]=cnt;}
inline void add1(int u,int v,int w) {vv[++ccnt]=v,ww[ccnt]=w,nn[ccnt]=ff[u],ff[u]=ccnt;}
inline void dijk() { memset(d,0x3f,sizeof(d));
priority_queue<pair<int,int> > q; q.push(mp(,ed)); d[ed]=;
while(q.size()) {
R u=q.top().second; q.pop(); if(vis[u]) continue;
for(R i=ff[u];i;i=nn[i]) { R v=vv[i];
if(d[v]>d[u]+ww[i]) d[v]=d[u]+ww[i],q.push(mp(-d[v],v));
}
}
}
struct node{ int u,g,h; node() {}
node(int uu,int gg,int hh) {u=uu,g=gg,h=hh;}
bool operator <(const node& y) const {return g+h>y.g+y.h;}
};
inline int Astar() { if(d[st]==Inf) return -;
priority_queue<node> q; q.push(node(st,,d[st]));
while(q.size()) {
register node crt=q.top(); q.pop(); R u=crt.u; ++c[u];
if(c[u]>k) continue; if(u==ed&&c[u]==k) return crt.g;
for(R i=fir[u];i;i=nxt[i]) q.push(node(vr[i],crt.g+w[i],d[vr[i]]));
} return -;
}
signed main() {
n=g(),m=g();
for(R i=,u,v,w;i<=m;++i) u=g(),v=g(),w=g(),add(u,v,w),add1(v,u,w);
st=g(),ed=g(),k=g(); st==ed?++k:k; dijk(); printf("%d\n",Astar());
}

2019.04.27

POJ2449 Remmarguts' Date A*算法的更多相关文章

  1. [poj2449]Remmarguts' Date(spfa+A*)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Remmarguts' Date Time Limit: 4000MS   Mem ...

  2. poj2449 Remmarguts' Date【A*算法】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303855.html   ---by 墨染之樱花 [题目链接]:http://poj.org/ ...

  3. [poj2449]Remmarguts' Date(K短路模板题,A*算法)

    解题关键:k短路模板题,A*算法解决. #include<cstdio> #include<cstring> #include<algorithm> #includ ...

  4. POJ2449 Remmarguts' Date

    "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. ...

  5. POJ2449 Remmarguts' Date 第K短路

    POJ2449 比较裸的K短路问题 K短路听起来高大上 实际思路并不复杂 首先对终点t到其他所有点求最短路 即为dist[] 然后由起点s 根据当前走过的距离+dist[]进行A*搜索 第k次到达t即 ...

  6. poj2449 Remmarguts' Date K短路 A*

    K短路裸题. #include <algorithm> #include <iostream> #include <cstring> #include <cs ...

  7. 图论(A*算法,K短路) :POJ 2449 Remmarguts' Date

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 25216   Accepted: 6882 ...

  8. poj 2449 Remmarguts' Date(第K短路问题 Dijkstra+A*)

    http://poj.org/problem?id=2449 Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Subm ...

  9. poj 2449 Remmarguts' Date 第k短路 (最短路变形)

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33606   Accepted: 9116 ...

随机推荐

  1. 459. Repeated Substring Pattern 判断数组是否由重复单元构成

    [抄题]: Given a non-empty string check if it can be constructed by taking a substring of it and append ...

  2. Net-tools

    一.简介 Net-tools 包含如下程序,构成了 Linux 网络的基础. arp用来操作核心的ARP(地址解析协议)的高速缓存,通常用来增加.删除一个条目以及转储ARP高速缓存. dnsdomai ...

  3. UCOSII在STM32F407上的移植

    1.ucosii移植准备工作 1.1准备基础工程: 移植的时候需要一个基础工程,为了方便起见我们就选取跑马灯实验,作为ucossii移植的基础工程. 1.2Ucossii源码: 1)Micrium官网 ...

  4. [原创]编译CLANG时遇到问题的解决办法

    CLANG备忘录: 1.编译时遇到 LINK1123 错误尝试使用其他版本的VS编译,可以有效解决这个问题 2.编译时遇到 Unexpectedfailure executing llvm-build ...

  5. IE6支持兼容max-height、min-height CSS样式

    1.IE6支持max-height解决方法   -   TOP IE6支持最大高度解决CSS代码: .yangshi{max-height:1000px;_height:expression((doc ...

  6. css总结9:内边距(padding)和外边距(margin)

    1 css总结9:内边距和外边距 通过css总结8:盒子模型可知:内边距(padding),外边距(margin).可以影响盒子在浏览器的位置. 1.1 padding使用:{padding:上 右 ...

  7. web大文件上传控件-监控f_create流程-Xproer.HttpUploader6

    监控f_create流程 1.打开ie,f12 2.启动网络监控 点击开始捕获 上传文件,然后查看监控 将监控信息转到详细视图 向f_create提交的数据 f_create返回值

  8. SharePoint配置网站集的审核设置

    配置网站集的审核设置 您可以使用 Microsoft SharePoint Server 2010 的审核功能来跟踪哪些用户对网站集的网站.内容类型.列表.库.列表项和库文件执行了哪些操作.了解谁对哪 ...

  9. DB2 添加license

    DB2 - DB2COPY1 - DB2-0 服务不能启动报的错是这样的:Microsoft Management Console   Windows 不能在 本地计算机 启动 DB2 - DB2.有 ...

  10. c# 将json转换为DataTable

    /// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...