bzoj1706: [Usaco2007 nov]relays Cow relay run (floyd+ new posture)

Source: Internet
Author: User

The main idea: there is a T (t<=100) bar without the edge connection two points, the S to e just through the N (n<=10^7) path of the minimum distance.

The first reaction layer chart, but a look at N on the crazy, will not write. After reading the puzzle to know can play like this ...

First there are 100 sides with a maximum of 200 points, but the points numbered to 1000, so discretization a bit.

any positive integer can be added with a power of 2, so first turn N into 2, and the bitwise considerations. Dist[i][j][k] means that the shortest distance from J to K is just passing through the 2^i bar, then dist[i,j,k]=min{dist[i-1][j][l]+dist[i-1][l][k]}. With a similar quick power method, if the 2 binary n This bit is 1, the answer array G and Dist run Floyd (Min{g[i-1][j][l]+dist[i-1][l][k]}), otherwise dist himself and run (min{dist[i-1][j][l ]+DIST[I-1][L][K]}) so that the sub-G is the minimum distance to run the N path .

The code is as follows:

typeMap=Array[1.. +,1.. +] ofLongint;varN,t,s,e,i,j,k,len,x,y,tot:longint; C,d,g:Array[1.. +,1.. +] ofLongint; Num:Array[1.. +] ofLongint;procedureMergevara,b:map);varI,j,k:longint;beginFillchar (C,sizeof (c), the);  fork:=1  toTot Do   fori:=1  toTot Do   forj:=1  toTot Do  ifC[I,J]&GT;A[I,K]+B[K,J] ThenC[i,j]:=a[i,k]+B[k,j]; A:=C;End;procedureWork ;beginFillchar (G,sizeof (g), the);  fori:=1  toTot Dog[i,i]:=0;  whileN>0  Do  begin    ifN and 1=1  Thenmerge (g,d);    Merge (D,d); N:=n>>1; End; Writeln (G[num[s],num[e]);End;beginreadln (n,t,s,e); Fillchar (d,sizeof (d), the);  fori:=1  toT Do  beginreadln (len,x,y); ifnum[x]=0  Then    beginInc (TOT); Num[x]:=tot; End; ifnum[y]=0  Then    beginInc (TOT); Num[y]:=tot; End; D[num[x],num[y]]:=len;d[num[y],num[x]]:=Len; End; work;End.
View Code

bzoj1706: [Usaco2007 nov]relays Cow relay run (floyd+ new posture)

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.