poj2387Til the Cows Come Home(dijkstra)

PyTorch 面试题及详细答案120题(54-70)-- 模型训练与评估 本文介绍了PyTorch模型训练的基本流程和核心概念。主要内容包括: 模型训练基本流程:通过代码示例展示了数据准备、模型定义、损失函数和优化器选择、训练循环(前向传播、反向传播、参数更新)的完整过程,并包含验证集评估的实现。 训练过程中的关键概念: Epoch:完整遍历一次训练集 Batch:将数据分成小批次 Iteration:一个Batch的参数更新过程 三者关系:1 Epoch = N/B Batch = N/B Iteration(N为样本数,B为batch_size) PyTorch数据加载机制: 阅读详情
Til the Cows Come Home
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 29627 Accepted: 9964

Description

Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. 

Farmer John's field has N (2 <= N <= 1000) landmarks in it, uniquely numbered 1..N. Landmark 1 is the barn; the apple tree grove in which Bessie stands all day is landmark N. Cows travel in the field using T (1 <= T <= 2000) bidirectional cow-trails of various lengths between the landmarks. Bessie is not confident of her navigation ability, so she always stays on a trail from its start to its end once she starts it. 

Given the trails between the landmarks, determine the minimum distance Bessie must walk to get back to the barn. It is guaranteed that some such route exists.

Input

* Line 1: Two integers: T and N 

* Lines 2..T+1: Each line describes a trail as three space-separated integers. The first two integers are the landmarks between which the trail travels. The third integer is the length of the trail, range 1..100.

Output

* Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.

Sample Input

5 5
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100

Sample Output

90

Hint

INPUT DETAILS: 

There are five landmarks. 

OUTPUT DETAILS: 

Bessie can get home by following trails 4, 3, 2, and 1.

Source



现在写单源最短距离越来越喜欢用堆来优化了,跑的时间明显快了


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
const int N=1010;
struct edge{int to,cost;};
typedef pair<int,int> p;
vector<edge> g[N];
int dis[N];
const int inf=10000000;
void dijkstra(int s)
{
    fill(dis,dis+N,inf);
    dis[s]=0;
    priority_queue<p> que;
    que.push(make_pair(0,s));
    while(!que.empty())
    {
        p p1=que.top();que.pop();
        int x=p1.first;
        int y=p1.second;
        for(int i=0;i<g[y].size();i++)
        {
            edge e=g[y][i];
            if(dis[e.to]>dis[y]+e.cost)
            {
                dis[e.to]=dis[y]+e.cost;
                que.push(make_pair(dis[e.to],e.to));
            }
        }
    }
}
void init()
{
    for(int i=0;i<N;i++)
        g[i].clear();
}
int main()
{
    int T,N;
    while(scanf("%d%d",&T,&N)!=EOF)
    {
        init();
        for(int i=0;i<T;i++)
        {
            int aa,bb,cc;
            scanf("%d%d%d",&aa,&bb,&cc);
            edge tmp;
            tmp.to=bb;
            tmp.cost=cc;
            g[aa].push_back(tmp);
            tmp.to=aa;
            g[bb].push_back(tmp);
        }
        dijkstra(N);
        printf("%d\n",dis[1]);
    }
    return 0;
}


























elevation mapping算法3之使用D435i相机离线或在线订阅点云和tf关系生成高程图 本文主要学习使用D435i相机发出的点云作为高程图的点云输入,如何离线输入点云生成高程图,进一步学习如何在线订阅点云生成高程图。 阅读详情

相关推荐

Claude Code VSCode集成开发指南:AI编程助手完整配置

Claude Code与Visual Studio Code的深度集成为开发者提供了强大的AI编程支持。本文详细介绍Claude Code VSCode扩展的安装配置、功能特性和实际应用方法。通过完整的配置流程和代码示例,帮助开发者充分利用Claude AI的智能编程能力。文章涵盖从环境搭建到高级功能应用的完整指南,包括代码自动补全、智能重构、实时代码分析等核心功能的使用技巧,以及与现有开发工作流的整合方案。

2501_93058131的博客 5983

POJ 2387 Til the Cows Come Home【dijkstra模板题】

POJ 2387 Til the Cows Come Home 题目大意: 无向图中,从点n到点1的最短路径 具体思路: dijkstra,考虑重边 注意下标减1,建议下次还是不使用0号,便于理解 具体代码: #include<iostream> #include<cstdio> #include<stdlib.h> #include<string>...

指弹键盘哼民谣 893

EEGNet 网络代码解析与实战复现指南

本文详细解析了EEGNet这一轻量级卷积神经网络的结构与设计思想,重点阐述了其利用深度可分离卷积高效处理脑电信号的原理。文章提供了基于PyTorch的完整代码复现指南,包括网络搭建、数据模拟、训练调试及关键参数解析,旨在帮助读者掌握EEGNet的代码复现技巧,并将其应用于脑机接口等实际场景。

honey的博客 532

【POJ 2387 --- Til the Cows Come Home】dijkstra

【POJ 2387 --- Til the Cows Come Home】dijkstra 题目来源:点击进入【POJ 2387 — Til the Cows Come Home】 Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible bef...

来日浅谈的博客 508

在LinuxMint 22.1(Ubuntu24.04)上安装使用同花顺远航版

Linux用户成功在LinuxMint22.1系统上通过Wine9.0运行同花顺远航版,解决了长期困扰的股票行情软件问题。此前Linux原生版同花顺功能简陋且停止更新,Wine版通达信存在显示问题。作者作为自由软件支持者,通过调整Wine配置文件解决了高分屏显示异常问题,实现了远航版的正常使用。期待同花顺能重启Linux原生版开发,支持更多处理器架构,完善国产软件生态。该方案为Linux股票软件用户提供了实用参考。

5136

Win10/Win11共享打印机0x00000709终极修复指南:从注册表到LPD协议的全面解决方案

本文提供了Win10/Win11共享打印机0x00000709错误的终极修复指南,涵盖从注册表修改到LPD协议的全面解决方案。通过详细分析错误根源、基础修复四步法、高阶LPD协议方案及企业级深度修复策略,帮助用户彻底解决打印机共享问题,提升局域网打印效率。

weixin_33724046的博客 311

POJ2387 Til the Cows Come Home【最短路径+Dijkstra算法】

Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 110837 Accepted: 35583 Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the mornin

海岛Blog 1128

基于R语言的现代贝叶斯统计学方法(贝叶斯参数估计、贝叶斯回归、贝叶斯计算)实践

贝叶斯统计学是一门基本思想与传统基于频率思想的统计学完全不同的统计学方法;它以其灵活性和先进性在现代的统计学中占据着重要的地位。贝叶斯统计学是开展科学研究不可缺少的重要手段,但是,因为其思想、技术和方法都与传统统计学有着较大区别;且其计算中涉及马尔科夫、蒙特卡罗和吉布斯采样等现代计算方法,对使用者经验和能力构成了很大的挑战。

AAIshangyanxiu的博客 679

[POJ2387](最短路dijkstra)Til the Cows Come Home

POJ2387Til the Cows Come Home 题目 Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her be...

Z7784562的博客 280

OpenClaw 从新手到中级完整教程【完整 持续更新版】

OpenClaw(曾用名 ClawdBot/Moltbot)是 2026 年最火的开源 AI Agent 项目,GitHub 已获得超过 68,000 星标。它不是普通的聊天机器人,而是一个真正能够执行任务的个人 AI 助理。

FeelTouch Labs 3115

PC 端微信页面拆分及 JavaFx 使用

一、前言 对于一个知识点的学习过程来说,往往使用自己熟悉的工具或方式才更易于上手。因为所有同类型的知识点在抛出复杂的流程拨云见日后,所能得到的几乎都是同样的设计思想和实现理论。 在 Java 语言桌面版开发中,直至目前共提供了三套 UI 开发方式;Awt、Swing、JavaFx,以及一些扩展组件 SWT 等。在这三套 UI 组件中,JavaFx 是最新也是最为好用的,因为他提供了丰富的功能,以及...

bugstack虫洞栈 3610

【POJ 2387 --- Til the Cows Come Home】dijkstra || dijkstra堆优化 || SPFA

【POJ 2387 --- Til the Cows Come Home】dijkstra || dijkstra堆优化 || SPFA Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes ...

来日浅谈的博客 510

全面认识PFC和LLC

想象一下,你在拉一辆车,如果你的力气都用在推动车子前进的方向上,这样拉车会比较轻松。而如果你的力气用在不正确的方向,比如侧向、斜向,那就需要更大的力气才能推动车子。PFC就是在帮助电流“朝着正确的方向”流动,这样可以用更少的能量做更多的事情,减少无用的功率损耗。PFC负责将电流方向对齐,让电源效率更高,而LLC负责电压的高效转换,两者配合可以在更宽的负载范围内保持高效率。综上所述,PFC LLC电路是一种高效的电源转换电路,通过PFC模块和LLC模块的组合,实现了从交流电到直流电的高效转换。

weixin_43199439的博客 6098

POJ2387::Til the Cows Come Home dijkstra算法

Dijkstra算法 Dijkstra算法大致上是利用贪心思想实现的,首先把起点到所有点的距离存下来找个最短的,然后遍历一遍看通过刚刚找到的距离最短的点作为中转点会不会更近,如果更近了就更新距离,这样把所有的点遍历之后就存下了起点到其他所有点的最短距离。然后将最短点的距离输出。 下面咱们来看一下这个题: Til the Cows Come Home POJ - 2387 Bessie is out...

weixin_43620849的博客 894

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ 2387 Til the Cows Come Home(dijkstra)

Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep...

邵光亮的博客 13万+

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【贪心】Dijkstra-POJ2387 Til the Cows Come Home

题目 http://poj.org/problem?id=2387 问题分析 这个题可以把地标作为顶点,把牛的踪迹作为边,顶点数为n,边数为t,那么所求就是第n个顶点到第一个顶点的最短路长度。 算法 算法核心 本题采用Dijkstra算法,Dijkstra算法是求最短路的贪心算法。有两个点集,设顶点总体为集合V,集合U初始为空,先确定起始顶点,将其加入集合U,然后在集合V中找到离起点最近的顶点,将...

vxiao_shen_longv的博客 206

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ2387-Til the Cows Come Home Dijkstra

Til the Cows Come HomeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 68691 Accepted: 23025DescriptionBessie is out in the field and wants to get back to the barn to get as much sleep as pos...

imbabao的博客 268

poj 2387 Til the Cows Come Home dijkstra

C - Til the Cows Come Home Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Bessie is ou

fanesemyk的博客 385

poj 2387 Til the Cows Come Home dijkstra

题意: 贝西在田里,想在农夫约翰叫醒她早上挤奶之前回到谷仓尽可能多地睡一觉。贝西需要她的美梦,所以她想尽快回来。 农场主约翰的田里有n(2<=n<=1000)个地标,唯一编号为1…n。地标1是谷仓;贝西整天站在其中的苹果树林是地标n。奶牛在田里行走时使用地标间不同长度的T(1<=t<=2000)双向牛道。贝西对自己的导航能力没有信心,所以一旦开始,她总是沿着一条从开始到结...

duanyuchen的博客 304

poj 2387 Til the Cows Come Home 【dijkstra】

Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48857   Accepted: 16615 Description Bessie is out in the field and wants to get back t

逝去的时光 216

POJ2387 Til the Cows Come Home——Heap+dijkstra

标准的 Heap_dijkstra,稍微有些恶心,但是并不难写。 CODE Program POJ2387;//By_Poetshy Const maxn=1005; Var i,j,k,m,n,p,q :Longint; pre,other,la

这个诗人不懂浪漫 895

POJ2387 Til the Cows Come Home【Dijkstra】

Til the Cows Come Home 最短路落题,如果是邻接表存图,则要小心重边。换作是链式前向星存图就没事了。 #include<algorithm> #include<iostream> #include<cstring> #include<iomanip> #include<cstdio> #include<string> #include<vector> #include<cmath&g...

lllllan 191

Dijkstra-POJ-2387-Til the Cows Come Home

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Input Output Sample Input Sample Output Hint

XLJ_XLJ的博客 1992

Til the Cows Come Home//POJ - 2387//dijkstra

Til the Cows Come Home//POJ - 2387//dijkstra 题目 Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bes...

salty_fishman的博客 218

POJ 2387 —— Til the Cows Come Home 裸dijkstra

原题:http://poj.org/problem?id=2387 题意:有T条路,n个点;给出每条路的花费,问从n 到 1的最小花费; 注意:1、无向图;2、有重边;3、输入T  n,边在前,点在后; #include #include #include #include #define inf 1e9 using namespace std; const int maxn = 1

0x3f3f3f3f 437

POJ 2387 Til the Cows Come Home(SPFA||Dijkstra)

POJ 2387 Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie n...

muyu__的博客 231
上一篇: hdoj3549 Flow Problem(裸的网络流)
下一篇: hdoj1532Drainage Ditches(网络流)
IT旅行
博客等级 码龄12年 3粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值