POJ 2449 Remmarguts' Date
来源:互联网 发布:淘宝卖家最严重的报复 编辑:程序博客网 时间:2024/05/17 19:20
Description
“Good man never makes girls wait or breaks an appointment!” said the mandarin duck father. Softly touching his little ducks’ head, he told them a story.
“Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One day their neighboring country sent them Princess Uyuw on a diplomatic mission.”
“Erenow, the princess sent Remmarguts a letter, informing him that she would come to the hall and hold commercial talks with UDF if and only if the prince go and meet her via the K-th shortest path. (in fact, Uyuw does not want to come at all)”
Being interested in the trade development and such a lovely girl, Prince Remmarguts really became enamored. He needs you - the prime minister’s help!
DETAILS: UDF’s capital consists of N stations. The hall is numbered S, while the station numbered T denotes prince’ current place. M muddy directed sideways connect some of the stations. Remmarguts’ path to welcome the princess might include the same station twice or more than twice, even it is the station with number S or T. Different paths with same length will be considered disparate.
【题目分析】
A*算法。把每一个状态加入一个堆。然后乐观的估价。当终点第k次出现的,就得到了答案。
【代码】
#include<iostream>#include<queue>#define MAXN 1001using namespace std;struct node{ int p,g,h; bool operator < (node a) const { return a.g+a.h<g+h; } };struct node1{ int x,y,w,next; }line[MAXN*100],line1[MAXN*100];int n,m,i,link[MAXN],link1[MAXN],g[MAXN],s,e,k;bool used[MAXN];priority_queue<node> myqueue; void djikstra(){ int i,k,p; memset(used,0,sizeof(used)); memset(g,0x7F,sizeof(g)); g[e]=0; for (p=1;p<=n;p++) { k=0; for (i=1;i<=n;i++) if (!used[i] && (!k || g[i]<g[k])) k=i; used[k]=true; k=link1[k]; while (k) { if (g[line1[k].y]>g[line1[k].x]+line1[k].w) g[line1[k].y]=g[line1[k].x]+line1[k].w; k=line1[k].next; } } return ; }int Astar(){ int t,times[MAXN]; node h,temp; while (!myqueue.empty()) myqueue.pop(); memset(times,0,sizeof(times)); h.p=s; h.g=0; h.h=0; myqueue.push(h); while (!myqueue.empty()) { h=myqueue.top(); myqueue.pop(); times[h.p]++; if (times[h.p]==k && h.p==e) return h.h+h.g; if (times[h.p]>k) continue; t=link[h.p]; while (t) { temp.h=h.h+line[t].w; temp.g=g[line[t].y]; temp.p=line[t].y; myqueue.push(temp); t=line[t].next; } } return -1; }int main(){ scanf("%d%d",&n,&m); memset(link,0,sizeof(link)); memset(link1,0,sizeof(link1)); for (i=1;i<=m;i++) { scanf("%d%d%d",&line[i].x,&line[i].y,&line[i].w); line[i].next=link[line[i].x]; link[line[i].x]=i; line1[i].x=line[i].y; line1[i].y=line[i].x; line1[i].w=line[i].w; line1[i].next=link1[line1[i].x]; link1[line1[i].x]=i; } scanf("%d%d%d",&s,&e,&k); if (s==e) k++; djikstra(); printf("%d\n",Astar()); return 0; }
- poj 2449 Remmarguts' Date
- POJ 2449 Remmarguts' Date
- POJ 2449 Remmarguts' Date
- poj 2449 Remmarguts' Date
- POJ 2449: Remmarguts' Date
- POJ 2449 Remmarguts' Date
- POJ-2449Remmarguts' Date
- POJ 2449 Remmarguts' Date
- POJ 2449 Remmarguts' Date
- POJ 2449 Remmarguts' Date
- POJ 2449 Remmarguts' Date
- poj-2449-Remmarguts' Date-A
- POJ 2449 Remmarguts' Date A* -
- Remmarguts' Date poj 2449 A*
- POJ 2449 Remmarguts' Date A*算法
- Poj 2449 Remmarguts' Date(Astar K短路)
- POJ 2449 Remmarguts' Date Dij +A*
- POJ 2449 Remmarguts' Date k短路
- CSAPP: Cache Lab
- 源码-PL/SQL从入门到精通-第二章-PL/SQL基本概念-Part 2
- HDU4497GCD and LCM ——算数基本定理
- 解决Eclipse中SVN版本信息不显示的问题
- html适应移动端设置
- POJ 2449 Remmarguts' Date
- 没有了剪辑和台本,papi酱为何要“强行”直播
- C#中OpenFileDialog获取文件名和文件路径的常用方法
- Qt学习之路(tip): Qt容器和算法拾遗
- iOS 第三方框架大全
- mysql、oracle、sqlserver中只显示前几条记录的语法
- sql 语句的拼接
- 让你不再害怕指针
- [组合计数] BZOJ 3505 [Cqoi2014]数三角形