日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

TYVJ1356(腾讯大战360)

發(fā)布時(shí)間:2023/12/20 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TYVJ1356(腾讯大战360) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
算法:最短路

求兩遍最短路,一個(gè)是從起點(diǎn)走向終點(diǎn),另一個(gè)從終點(diǎn)走向起點(diǎn),記錄下每次走每個(gè)點(diǎn)的最短路,然后枚舉一遍,對(duì)于每個(gè)點(diǎn),找一個(gè)最大的最短路看能否更新min。

program P1356;constmaxn=10000;typeatp=recordy,dis,next:longint;end;varhead,tail,n,m,tot,st,ed:longint;b:array [0..maxn] of boolean;first,que:array [0..maxn] of longint;v:array [0..1,0..maxn] of longint;map:array [0..maxn] of atp;procedure init; vari,x,y,dis:longint; beginfillchar(v,sizeof(v),100);readln(n,m);for i:=1 to m dobeginreadln(x,y,dis);inc(tot);map[tot].y:=y;map[tot].dis:=dis;map[tot].next:=first[x];first[x]:=tot;inc(tot);map[tot].y:=x;map[tot].dis:=dis;map[tot].next:=first[y];first[y]:=tot;end;readln(st,ed); end;procedure SPFA(x:longint); vart:longint; beginfillchar(b,sizeof(b),false);fillchar(que,sizeof(que),0);if x=0 thenbeginv[x,st]:=0;que[1]:=st;b[st]:=true;endelsebeginv[x,ed]:=0;que[1]:=ed;b[ed]:=true;end;head:=0;tail:=1;while head<tail dobegininc(head);t:=first[que[head]];while t<>0 dobeginif v[x,que[head]]+map[t].dis<v[x,map[t].y] thenbeginv[x,map[t].y]:=v[x,que[head]]+map[t].dis;if not b[map[t].y] thenbegininc(tail);que[tail]:=map[t].y;b[map[t].y]:=true;end;end;t:=map[t].next;end;b[que[head]]:=false;end; end;function max(x,y:longint):longint; beginif x>y then exit(x) else exit(y); end;procedure outit; varmin,i:longint; beginmin:=maxlongint;for i:=1 to n do if max(v[0,i],v[1,i])<min then min:=max(v[0,i],v[1,i]);if min=v[0,0] then writeln('Peace!') else writeln(min); end;beginassign(input,'P1356.in'); reset(input);assign(output,'P1356.out'); rewrite(output);init;SPFA(0);SPFA(1);outit;close(input); close(output); end.

總結(jié)

以上是生活随笔為你收集整理的TYVJ1356(腾讯大战360)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。