POJ 2387 Til the Cows Come Home

POJ - 2387:Til the Cows Come Home Til the Cows Come Home 来源:POJ 标签:最短路径问题,迪杰斯特拉算法 参考资料: 相似题目: 题目 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 mor... 阅读详情

农夫囧的头号后宫母牛背时迷路了。给定一张无向图,背时在标号为n的节点。问背时回标号1的节点的最短路有多长。

最短路,用dijkstra的话会比较麻烦,因为这题可能有重边。所以就要用到传说中号称快速求最短路的SPFA算法。

诶。。其实是第一次写spfa,把模板放在这里,以后方便复习。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
struct edge
{
    int u;
    int v;
    int w;
};
edge e[5000];
vector<int> v[2100];
queue<int> q;
bool inque[2100];
int le,dist[2100];
int spfa(int sta,int tar)
{
    int t,i,te;
    while (!q.empty())
        q.pop();
    memset(inque,false,sizeof(inque));
    memset(dist,127,sizeof(dist));
    q.push(sta);
    inque[sta]=true;
    dist[sta]=0;
    while (!q.empty())
    {
        t=q.front();
        q.pop();
        inque[t]=false;
        for (i=0; i<v[t].size(); i++)
        {
            te=v[t][i];
            if (dist[e[te].v] > dist[t]+e[te].w)
            {
                dist[e[te].v]=dist[t]+e[te].w;
                if (inque[e[te].v] == false)
                {
                    inque[e[te].v]=true;
                    q.push(e[te].v);
                }
            }
        }
    }
    return dist[tar];
}
int main()
{
    int n,t,i,j,t1,t2,t3;
    scanf("%d%d",&t,&n);
    le=0;
    for (i=1; i<=n; i++)
        v[i].clear();
    for (i=0; i<t; i++)
    {
        scanf("%d%d%d",&t1,&t2,&t3);
        v[t1].push_back(le);
        e[le].u=t1;
        e[le].v=t2;
        e[le].w=t3;
        le++;
        v[t2].push_back(le);
        e[le].u=t2;
        e[le].v=t1;
        e[le].w=t3;
        le++;
    }
    printf("%d\n",spfa(1,n));
}


cadence virtuoso 激励信号源 vpulse,vpwl,vsin,vsource信号源介绍 阅读详情

相关推荐

win10删除vmware12后,重新安装失败(遗留注册表问题)解决总结

之前安装过一次VMware虚拟机,后来由于某些已遗忘原因把它卸载了,但是没有卸载完全,为以后安装留下了一些麻烦,现在根据我google很多内容总结后写下了自己的解决办法。 一些我搜的的可以用的VM12的注册码 5A02H-AU243-TZJ49-GTC7K-3C61N ZZ510-DYX47-48ERP-D6XZG-YCKU2 YV5MU-2FX5H-M841P-LZX5X-PYHX8

Jeason的博客 2万+

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

AutoDock Vina 对接计算(大批量)

AutoDock Vina是一种用于计算生物分子之间相互作用的计算工具,主要用于蛋白质和小分子(通常是潜在药物分子)之间的对接研究。它可以用于虚拟筛选、药物设计和生物分子结合位点的预测等多个应用领域。

MurphyStar的博客 1万+

【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

告别Modern Standby烦恼:在Windows 11中手动启用S3睡眠模式的完整指南

本文详细介绍了如何在Windows 11中手动启用S3睡眠模式,解决Modern Standby(S0模式)导致的笔记本睡眠后耗电问题。通过注册表修改、电源选项调整、BIOS设置等步骤,帮助用户恢复传统深度睡眠功能,显著提升电池续航表现。

weixin_30271335的博客 559

PyRoki:机器人运动学优化库入门教程

PyRoki:模块化机器人运动学优化工具包 本文介绍了PyRoki,一个模块化、可扩展且跨平台的机器人运动学优化工具包。PyRoki通过统一变量和成本函数接口,简化了逆运动学、轨迹优化和运动重定向等任务的实现,支持CPU、GPU和TPU加速。实验表明,PyRoki在批量逆运动学任务中比现有GPU加速库cuRobo快1.4-1.7倍,且收敛误差更低。其模块化设计支持快速集成新成本函数,并通过交互式可视化工具优化参数配置。PyRoki开源发布,为机器人运动优化提供了灵活高效的解决方案。

机器人控制与仿真应用 1293

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

AUTOSAR知识点 之 XCP (三):XCP功能描述

记录一下XCP使用时候的功能包含命令时序、错误码表、事件描述以及对规范的记录。XCP的图示如下从上图就可以看出数据流的流向CAN-CANIF-XCP,发送反之。XCP的状态机如下。

梦想技术家 3077

[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

git clone出现fatal: unable to access Failed to connect to github.com port 443: Timed out解决方案

本文主要介绍了git clone出现fatal: unable to access Failed to connect to github.com port 443: Timed out解决方案,希望能对使用git的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 23万+

基于matlab的图像HOG特征提取算法仿真

方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子。它通过计算和统计图像局部区域的梯度方向直方图来构成特征。Hog特征结合SVM分类器已经被广泛应用于图像识别中,尤其在行人检测中获得了极大的成功。需要提醒的是,HOG+SVM进行行人检测的方法是法国研究人员Dalal在2005的CVPR上提出的,而如今虽然有很多行人检测算法不断提出,但基本都是以HOG+SVM的思路为主。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 730

POJ2387-Til the Cows Come Home

POJ2387-Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55360 Accepted: 18793 DescriptionBessie is out in the field and wants to get back to the barn to g

君安在AreYouWell 447

国科大学习资料--人工智能原理与算法-2020年期末考试题解析(学长整理)

国科大学习资料–人工智能原理与算法-2020年期末考试题解析 张文生老师主讲 试卷共有6道题,题目不难,希望大家能取得好的成绩。 3.9 传教士和野人问题。三个传教士和三个野人在河的一岸,有一条能载一个人或者两个人的船。请设法使所有人都渡到河的另一岸,要求在任何地方野人数都不能多于传教士的人数。这个问题在AI领域中很有名,是因为它是第一个从分析的观点探讨问题形式化的论文的主题(Amarel,1968)。 a. 请对该问题进行详细形式化,只描述确保该问题求解所必需的特性。画出完整的状态空间图。 b. 应用合适

无名何许人的博客 4788

POJ2387-Til the Cows Come Home-最短路

POJ2387-Til the Cows Come Home-最短路DescriptionBessie 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

君安在AreYouWell 453

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

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

传送门:POJ 2387 Til the Cows Come Home 千万看清点数和路径数的输入顺序。否则。你会像我一样WA和RE一个下午。 #include <iostream> #include <vector> #include <queue> #include <string.h> #define INF 0x3f3f3f3f us...

坤斤拷的博客 183

POJ2387::Til the Cows Come Home dijkstra算法

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

weixin_43620849的博客 894

poj 2387 Til the Cows Come Home

直接spfa处理即可 //poj 2387 Til the Cows Come Home /* * spfa */ //licatweijei #include using namespace std; #define INF 1000000 #define MAXE 10100 #define MAXV 1010 #include #include double

LiWeiJie的专栏 605

POJ T2387 Til the Cows Come Home

                 POJ T2387 Til the Cows Come Home   模板裸题,注意点都在注释了....... Spfa写法 #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;queue&gt; #define maxn 1005 #define INF 0x3f3f3f3f usi...

Mr__Charles的博客 192

最短路练习1 poj 2387 Til the Cows Come Home

题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 51700   Accepted: 17474 Description Bessie is o

Accepted 512

POJ 2387 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, so she wants t

Sino_Crazy_Snail的小窝 1252

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万+

【POJ】2387 Til the Cows Come Home

题目链接:http://poj.org/problem?id=2387 题意:求从1到n的最短路 题解:板子题。spfa。 代码: 1 #include<iostream> 2 #include<stack> 3 #include<vector> 4 #include<queue> 5 #in...

deze1991的专栏 106

poj 2387 Til the Cows Come Home

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

笨小孩的专栏 540
上一篇: BNUOJ 14362 Election Time
下一篇: OpenGL织梦之旅【第三章】第4节.glut键盘鼠标响应
plusplus7
博客等级 码龄15年 59粉丝 173原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值