2016 the way of garlic and the real-time traffic floyd+cdq of Baidu Map

Source: Internet
Author: User

Links: https://nanti.jisuanke.com/t/11217

The official:

Enumerationd (x, Y, z) < Span class= "Mclose" >  in  y< span class= "Strut" > , put  y  from this figure, Then the full source of the shortest possible, using the Floyd algorithm to do the above procedure < Span class= "base textstyle uncramped" >< Span class= "mpunct" > < Span class= "Strut bottom" >< Span class= "Katex-mathml" >.

< Span class= "base textstyle uncramped" >< Span class= "katex-html" >< The span class= "Mord mathit" >floyd algorithm can be an incremental process, although the first dimension is generally from  1k But the order of this enumeration does not affect the final result.

So if you can preprocess the  y, only  y  does not have a matrix enumerated in the first dimension of Floyd, the value of this matrix is not   < Span class= "base textstyle uncramped" >y  Point's full source shortest path.

So using divide and conquer, each time the point set is split into two halves, first with the first half of the points in the Floyd algorithm roll, and then recursive half point.

Then backtrack, using the last half of the points in the Floyd algorithm roll, recursion to the first half of the point. So that each state with only one point gets the matrix that only this point does not roll in the Floyd algorithm.

Time complexity of O(n^? 3?? logn).

Spit Groove: Before writing this problem, CDQ division only wrote three-dimensional partial-order template problem, the whole two-part of the writing is very few, later should be more write some

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<string>#include<stack>#include<vector>#include<map>#include<queue>#include<algorithm>#include<utility>using namespaceStd;typedefLong LongLL;Const intn=305;Const intinf=0x3f3f3f3f;intdp[ -][n][n],n,mp[n][n]; LL ret;voidCPYDP (intDEP) {   for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) Dp[dep][i][j]=dp[dep-1][i][j];}voidUpdateintDepintLintR) {   for(intk=l;k<=r;++k) for(intI=1; i<=n;++i) for(intj=1; j<=n;++j)if(dp[dep][i][j]>dp[dep][i][k]+Dp[dep][k][j]) dp[dep][i][j]=dp[dep][i][k]+dp[dep][k][j];}voidCdqintDepintLintR) {  if(l==R) {     for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) {        if(i==l| | J==L)Continue; if(Dp[dep][i][j]==inf) dp[dep][i][j]=-1; RET+=1ll*Dp[dep][i][j]; }    return; }  intM=l+r>>1; CPYDP (DEP+1), Update (dep+1, m+1, R); CDQ (DEP+1, l,m); CPYDP (DEP+1), Update (dep+1, l,m); CDQ (DEP+1, m+1, R);}intMain () {scanf ("%d",&N);  for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) {scanf ("%d", &dp[0][i][j]); if(dp[0][i][j]==-1) dp[0][i][j]=INF; } CDQ (0,1, N); cout<<ret<<Endl; return 0;}
View Code

2016 Garlic Road FLOYD+CDQ Baidu Map of the real-time road traffic and sub-treatment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.