3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 39 Solved: 14
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100
Sample Output
共有5个路标,贝茜可以依次经过路标4,3,2,1到家
HINT
Source
题解:么么哒又是一道双倍经验水题= =(HansBug:还有话说这不是最短路模板题么= =)
按照惯例,我还是贴两个代码,我只笑笑不说话
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
VAR
i,j,k,l,m,n,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
p:point;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
end;
begin
readln(m,n);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,l);
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),-);
c[]:=;f:=;r:=;d[]:=;g[]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=-) or (c[p^.g]>(c[d[f]]+p^.w)) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;inc(f);
end;
writeln(c[n]);
readln;
end.
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
VAR
i,j,k,l,m,n,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
p:point;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
end;
begin
readln(m,n);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,l);
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),-);
c[]:=;f:=;r:=;d[]:=;g[]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=-) or (c[p^.g]>(c[d[f]]+p^.w)) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;inc(f);
end;
writeln(c[n]);
readln;
end.
3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家的更多相关文章
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- Til the Cows Come Home(最短路)
Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- POJ2387 Til the Cows Come Home(SPFA + dijkstra + BallemFord 模板)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37662 Accepted ...
- POJ 2387 Til the Cows Come Home
题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K ...
- 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33015 Accepted ...
- POJ 2387 Til the Cows Come Home (最短路 dijkstra)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...
- BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Description 农夫 ...
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )
dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1 ...
- 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果
3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solv ...
随机推荐
- ImageView及其子类(一)
ImageView继承自View组件,它的主要功能是用于显示图片——实际上这个书法不太严谨因为他能显示的不仅是图片,任何Drawable对象都可以使用ImageView来显示.除此之外,ImageVi ...
- Java线程:总结
线程的状态转换图: new:新建状态 Runnable:就绪状态.线程对象创建后,其他线程调用了该对象的start()方法.该状态的线程位于可运行线程池中,变得可运行,等待获取CPU的使用权. Run ...
- flex chrome浏览器调试flex程序
flex chrome浏览器调试出现空白的解决方法: 1,为chrome安装flash player,禁用chrome自带的flash player:参考:http://www.jb51.net/ar ...
- Web项目或WCF发布IIS后,如何通过VS2010调试
在做项目的时候,例如WCF服务一般都会将WCF服务承载于控制台应用程序,或者WinForm窗体应用程序,因为这样可以直接在服务代码上打断点,然后就可以调试了.但是项目已经发布了,当然这里我用的本机进行 ...
- FlashPlayer11 异步解码 Bitmap
Flash Player 11引入了一个全新的功能是异步解码位图的功能,这个功能对某些类型的Flash应用会很有效,尤其是需要加载大分辨率的位图的相册或游戏会有显著效果,使用位图图像时,可以异步解码和 ...
- FMS用AS来实现拉流
application.onAppStart=function (){ this.myNC=new NetConnection(); this.myNC.onStatus=NC_onStatus; t ...
- css,html性能优化
css性能优化 CSS是负责布局和渲染的重要角色,漂亮的页面当然能够吸引用户.本文是自己在开发过程中总结的关于CSS与性能的关系,可能有不对之处,希望能够指出. ? 1.所有的样式尽量放在css文件中 ...
- A tutorial on Principal Components Analysis | 主成分分析(PCA)教程
A tutorial on Principal Components Analysis 原著:Lindsay I Smith, A tutorial on Principal Components A ...
- ABP入门系列(8)——Json格式化
ABP入门系列目录--学习Abp框架之实操演练 讲完了分页功能,这一节我们先不急着实现新的功能.来简要介绍下Abp中Json的用法.为什么要在这一节讲呢?当然是做铺垫啊,后面的系列文章会经常和Json ...
- [CSS3]学习笔记-文字与字体相关样式
1.给文字添加阴影 <!doctype html> <html> <head> <meta charset="utf-8"> < ...