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 ...
随机推荐
- Quartz_理解1
一.引言 quratz是目前最为成熟,使用最广泛的java任务调度框架,功能强大配置灵活.在企业应用中占重要地位.quratz在集群环境中的使用方式是每个企业级系统都要考虑的问题.早在2006年,在I ...
- Android仿微信朋友圈,全文收起功能,附源码
在众多的社交类软件中,朋友圈是必不可少的,可以与好友.同学等分享自己的日常和有意思的事情,在开发社交类App时,朋友圈发表的内容你不可能让他全部显示,全部显示的话用户体验度会非常不好,这时就要用到全文 ...
- matlab for循环应用(阶乘及the day of year)
一.N的阶乘 %脚本文件:test.m %N的阶乘 使用举例 % 定义变量 % ii ---循环变量,也就是循环次数 % N ---N的阶乘 % N_factorial --计算N的阶乘 clc;cl ...
- java udp socket通信(仅发送)
实现功能:客户端发送一个字符串(可以为汉字),服务器端接收并显示 服务器端程序: package udpServer; import java.io.*; import java.net.*; /** ...
- java 继承的学习(转)
转自:http://www.cnblogs.com/happyframework/p/3332243.html,非常感谢啊 public class test { /** * @param args ...
- Android注解学习(1)
对于注解这个概念刚开始不是很理解,翻阅了其他人博客,参考实现的例子开始理解与运用.以前刚开始的写android项目时,一般找定义控件并初始化控件都是调用findviewbyId,然而当一个布局页面(类 ...
- sql递归查询语句
sql Bom 递归查询: with t as(select * from Department where id=6union allselect a.* from Department a,t w ...
- Angular2的模块架构浅谈
引言angular2相比1引入了更完善的模块系统,回忆ng1的应用中通常在页面的html标签或body标签中添加ng-app节点,值为应用的模块名,整个应用都将围绕这个模块来展开,到了ng2,模块概念 ...
- java 解析json
例<解析评论> //post方式请求 String url=“http://product.dangdang.com/comment/comment.php?product_id=6056 ...
- IOS8 : UIAlertController
UIAlertController 和 UIAlertAction 用法: 1. 最简单的提醒视图: 这里我们实现一个最简单的提醒视图,包含1个标题,1行信息,1个按键,按下按键后,什么都不发生: ...