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 ...
随机推荐
- SVG的基础使用
SVG的基础使用: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...
- 部署AlwaysOn第一步:搭建Windows服务器故障转移集群
在Windows Server 2012 R2 DataCenter 环境中搭建集群之前,首先要对Windows服务器故障转移集群(Windows Server Failover Cluster,简称 ...
- js阻止表单提交的两种方法
下面直接看代码. <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- TV端:通过遥控器的点击实现图片的上下左右抖动的效果
做TV端有一段时间了,我看到别的TV上有一个通过遥控器的触摸板来控制一张图片的相应方向的抖动,感觉听新奇的,就试着做了一个分享一下: 转载注明出处:http://www.cnblogs.com/hyy ...
- JAVA构造函数的继承
1.子类中无参构造函数,可直接继承父类中无参构造函数,前提是所有变量均为public 如下:父类Student中有空构造函数Student(),子类Pupil中有空构造函数Pupil(),后者会继承前 ...
- Git 和 GitHub 使用
Git和GitHub的使用 Git是一款免费.开源的分布式版本控制系统. GitHub托管远程仓库,并提供一个web界面. 有2种协议支持从本地push代码到远程仓库. 一种是http,需要输入用户名 ...
- TCP/IP协议族(二) HTTP报文头解析
本篇博客我们就来详细的聊一下HTTP协议的常用头部字段,当然我们将其分为请求头和响应头进行阐述.下方是报文头每个字段的格式,首先是头部字段的名称,如Accept,冒号后方紧跟的是该字段名所对应的值,每 ...
- 微软Visual Studio二十周年:VS2017于3月7日发布
二十年前的今天,微软正式发布Visual Studio 97.如今二十年已经过去,微软宣布全新的Visual Studio 2017即将在美国当地时间3月7日正式发布. VS97是Visual Stu ...
- PHP文件上传处理
web中,文件上传是一个很常用的功能.如:上传头像.上传图片.这些提交到后台的图片都要交给后端处理.php提供了几个上传处理的函数,我把它们封装成类,以便日后使用. 处理流程(可能有不合理的地方,用时 ...
- ASP.NET MVC5 实现分页查询
对于大量数据的查询和展示使用分页是一种不错的选择,这篇文章简要介绍下自己实现分页查询的思路. 分页需要三个变量:数据总量.每页显示的数据条数.当前页码. //数据总量 int dataCount; / ...