当前位置 : 主页 > 网络编程 > 其它编程 >

POJ2502思维建图Dijkstra

来源:互联网 收集:自由互联 发布时间:2023-07-02
思维建图Dijkstra模板#include#include#include#include# //思维建图Dijkstra模板#include#include#include#include#include#includeusing namespace std;const double INF1e30;const int maxv210;bool visit[maxv];double dis[maxv],mmap[maxv][m
思维建图Dijkstra模板#include#include#include#include#

//思维建图Dijkstra模板#include#include#include#include#include#includeusing namespace std;const double INF1e30;const int maxv210;bool visit[maxv];double dis[maxv],mmap[maxv][maxv];struct Coordinate {double x,y;} coord[maxv];struct Node {int u;double dis;bool operatordis>rhs.dis;}} now,temp;double Distance(Coordinate a,Coordinate b) {return sqrt((a.x-b.x)*(a.x-b.x)(a.y-b.y)*(a.y-b.y));}void init() {memset(mmap,0x7f,sizeof mmap);//第一开始我第二个参数直接传的INFmemset(dis,0x7f,sizeof dis);//double类型要赋值7f才为极大memset(visit,false,sizeof visit);}void Dijkstra(int s,int n,double mmap[][maxv],double dist[maxv],bool visit[]) {//s是源点n是元素总个数本模板默认存储二维数组时按照[1][1]->[n][n]存储int i,v;dist[s]0;priority_queue pq;temp.dis0,temp.us;pq.push(temp);while(!pq.empty()) {temppq.top();pq.pop();if(visit[temp.u]true)continue;visit[temp.u]true;for(v1; vdist[temp.u]mmap[temp.u][v]) {dist[v]dist[temp.u]mmap[temp.u][v];now.uv;now.disdist[v];pq.push(now);}}}}int main(void) {#ifndef ONLINE_JUDGEfreopen("E:\\input.txt","r",stdin);#endif // ONLINE_JUDGEdouble v110000.0/60.0,v240000.0/60.0;while(~scanf("%lf%lf%lf%lf",2,cnt13,x,y;init();while(~scanf("%d%d",-1-1){cnt1n1;continue;}n;coord[n].xx;coord[n].yy;if(n!cnt1)mmap[n][n-1]mmap[n-1][n]min(mmap[n][n-1],Distance(coord[n],coord[n-1])/v2);}for(int i1;i 

上一篇:ios把毫秒值转换成日期
下一篇:没有了
网友评论