Silver Cow Party--poj3268(SPFA)

osg3.6.5---osgEarth3.2 实现数字地球的加载 目前我在网上找得比较多的是osgearth2.10及以下的版本及加载数字地球的方法,但是我使用的是osg3.6.5和osgEarth3.。但是3.x版本和2.x版本差别很大,主要区别在于2.x有7个主要库,而3.x版本只有osgEarth这一个库。所以,特别记录一下。后面我讲他集成到qt的窗体在上传更新新的代码。1.直接上源码pro文件和cpp文件。 阅读详情

Silver Cow Party
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 15533 Accepted: 7045

Description

One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.

Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.

Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?

Input

Line 1: Three space-separated integers, respectively: N, M, and X 
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.

Output

Line 1: One integer: the maximum of time any one cow must walk.

Sample Input

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

Sample Output

10

Hint

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.


题意大概是:有1-N头牛住在不同的地方,现在所有的牛要去参加银牛party,地点在X
有M条路(单向的)所有的牛都很懒,都要走最短的路去,最短的路回,求走的路最长的那头牛走的路程!


这个题挺好的!
要反向建图求去时的路程,正向建图求回来的路程!


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f
#define MAXN 1000+10
#define MAXM 200000+10
using namespace std;

int head[MAXN],vis[MAXN],dis[MAXN];
int n,m,x;
struct node 
{
	int from,to,weight,next;
 } edge[MAXM];
 void input()
 {
 	int i,a,c,b;
 	memset(head,-1,sizeof(head));
 	for(i=0;i<m;i++)
 	{
 		scanf("%d%d%d",&a,&b,&c);//反向建图
 		//edge[i]={b,a,c,head[b]};//这种写法在poj过不了!害我ce两次
 		edge[i].from=b;
 		edge[i].to=a;
 		edge[i].weight=c;
 		edge[i].next=head[b];
 		head[b]=i;
	 }
 }
 void spfa()
 {
 	memset(dis,INF,sizeof(dis));
 	memset(vis,0,sizeof(vis));
 	dis[x]=0;
 	vis[x]=1;
 	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int k=head[u];k!=-1;k=edge[k].next)
		{
			int v=edge[k].to;
			if(dis[v]>dis[u]+edge[k].weight)
			{
				dis[v]=dis[u]+edge[k].weight;
				if(!vis[v])
				{
					vis[v]=1;
					q.push(v);
				}
			}
		}
	 }
 }
 int main()
 {
 	int a[MAXN],b[MAXN];
 	while(scanf("%d%d%d",&n,&m,&x)!=EOF)
 	{
 		int i;
 		input();
 		spfa();
 		for( i=1;i<=n;i++)
 		//printf("++%d ",dis[i]);
 		a[i]=dis[i];
 		int t;
		memset(head,-1,sizeof(head));
 		for(i=0;i<m;i++)//正向建图
 		{
 			t=edge[i].from;
 			edge[i].from=edge[i].to;
 			edge[i].to=t;
 			edge[i].next=head[edge[i].from];
 			head[edge[i].from]=i;
		 }
		 spfa();
		for( i=1;i<=n;i++)
		a[i]+=dis[i];//往返路程相加
		
		int m=-1;
 		for(i=1;i<=n;i++)
 		m=m < a[i] ? a[i]:m;//求出最大的路程
 		printf("%d\n",m);
	 }
	 return 0;
 }
 


使用强化学习快速让AI学会玩贪食蛇游戏(轻量级二十分钟训练+代码) 如何让AI玩会贪食蛇,甚至比你厉害概述构建问题(强化学习求解的一般步骤)环境动作定义状态定义奖励设计训练奖励值收敛图效果代码 概述 所用技术:强化学习(Deep Reinforcement Learning),属于一种无监督学习,利用奖励rewardrewardreward教会智能体AgentAgentAgent在合适的场景做合适的决策。 采用算法:试过两种算法D3QN和离散版本的PPO算法,最终采用离散版本PPO算法+GAE(PPO是我用过的性能最好的算法之一) 编程语言与深度学习框架:Python3. 阅读详情

相关推荐

蛋白组学/磷酸化蛋白组学分析笔记-2

如何校正蛋白丰度?磷酸化组学质谱下机处理。

weixin_43029125的博客 1372

Silver Cow Party(好题)

给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x,除了牛x之外的牛,他们都有一个参加聚会并且回来的最短时间,从这些最短时间里找出一个最大值输出 Input Line 1: Three space-separated integers, respectively: N, M, and X Lines 2… M+...

weixin_44824383的博客 162

Visio中高效绘制空间坐标系的实用技巧

本文详细介绍了在Visio中从零开始高效绘制精准空间坐标系的实用技巧。文章摒弃了现成形状的局限,重点讲解了如何利用直线、箭头和文本框等基础工具,结合网格设置、绘图比例调整和图层管理,构建完全可控的三维坐标系。通过分步指南,帮助用户掌握刻度添加、标注对齐及模板创建等高级方法,从而在科研绘图与工程制图中实现专业级的视觉效果。

e3f4g5的博客 558

POJ 3268 Silver Cow Party (最短路)

Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10147   Accepted: 4497 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

weixin_33694172的博客 307

手把手教你用Microsoft AEC Challenge数据集训练自己的回声消除模型(附完整代码)

本文详细介绍了如何使用Microsoft AEC Challenge数据集训练专业的回声消除模型,包括环境准备、数据清洗、模型架构设计、训练流程和实际部署注意事项。通过完整的代码示例和实战指南,帮助开发者快速掌握AEC技术,提升语音通信系统的回声消除效果。

weixin_27697385的博客 456

从CentOS迁移到openEuler 24.03 LTS:手把手教你部署Java+MySQL+Redis+Nginx全栈环境

本文详细指导如何从CentOS迁移到openEuler 24.03 LTS,并部署Java+MySQL+Redis+Nginx全栈环境。涵盖系统配置、软件安装、性能优化及环境验证,助力企业级用户高效完成服务器迁移与部署。

weixin_26938645的博客 388

Silver Cow Party

One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way r

qdu2016207009的博客 178

别再只盯着时序了!聊聊SDC里那些容易被忽略的‘配角’命令:工作条件、线载模型与面积约束

本文深入探讨了SDC(设计约束)中常被忽视的关键命令,包括set_operating_conditions、set_wire_load_model和set_max_area。这些‘配角’命令在芯片设计中扮演着至关重要的角色,影响时序收敛、功耗和面积优化。文章通过实际案例和最佳实践,揭示了如何正确配置工作条件、选择线载模型以及动态调整面积约束,以提升设计质量和效率。

weixin_26875109的博客 208

POJ - 3268 Silver Cow Party(spfa)

One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way r

qqchanmingdexiaji的博客 343

BBR算法原理与实现深度解析

BBR算法通过重新定义拥塞控制的基本范式,为现代网络应用提供了突破性的解决方案。随着QUIC协议的普及和智能网卡技术的发展,BBR类算法将在边缘计算、云游戏、工业物联网等领域发挥更重要的作用。

程序猿老樊的博客 2418

工业视觉实战:用摄像头+AI高精度测量钢板尺寸(附深度分析)

摘要: 钢铁制造业正加速采用基于摄像头与深度学习的视觉测量技术,以取代传统人工测量,实现钢板长、宽、高(厚)的非接触、高精度在线检测。核心方案包括单目视觉(低成本但受限于变形)、双目/多目立体视觉(可精确测量变形钢板)及3D激光扫描(微米级精度)。系统精度受硬件(相机分辨率、镜头)、算法(亚像素技术)及环境稳定性共同影响,综合精度可达±0.1mm。实战中需重点解决热膨胀(需红外测温实时补偿)和钢板变形(必须采用三维方案)两大挑战,并通过工程化设计(散热、防振)确保系统可靠运行。该技术需融合光学、机械与算法,

数字人生 391

D - Silver Cow Party

题目链接:https://cn.vjudge.net/contest/289568#problem/D One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1…N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A tota...

不想起标题 420

《AgentScope-Java 深入浅出教程》第1章 AgentScope-Java 简介

AgentScope-Java 是一个面向智能体的编程框架,专门用于构建基于大语言模型(LLM)的 AI 应用程序。│ 你的业务应用 ││ AgentScope-Java 框架 ││ │ 智能体 │ │ 工具 │ │ 记忆 │ │ 模型 │ ││ LLM 服务 (DashScope/OpenAI/...) │能力说明类比ReAct 推理让智能体能够"思考"并"行动"就像人类思考后再做事工具调用让智能体能够执行外部操作就像人使用计算器、搜索引擎记忆管理让智能体能够记住对话历史。

步子哥的博客 592

POJ-3268 Silver Cow Party(最短路spfa算法)

POJ-3268 Silver Cow PartySilver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19989 Accepted: 9128DescriptionOne cow from each of N farms (1 ≤ N ≤ 1000) convenientl

废宅工程狮养成日志 421

OV9734 DATASHEET,完整规格书

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

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

【POJ3268】Silver Cow Party【spfa】

#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std ; #define Y second #define X first #defi

zkxwhanybz828的专栏 493

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

POJ 3268 Silver Cow Party(SPFA)

有 n 个点 m 条单向边,起点为 x,问从每一个点 i 到 x 的距离 + 从 x 到 i 的距离最大是多少 开始建一个有向图,再将有向图的起点与终点置换,两次以 x 为起点的 SPFA 即可 const int M=1e5+5; const int N=1000+5; int n,m,t; int i,j,k; vector<Pair> E[M]; bool inq[N]; int d[N]; void init() ...

C_Dreamy的博客 351

Silver Cow Party poj 3268 Dijkstra,spfa,+vector

Silver Cow Party poj 3268 Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 17173        Accepted: 7845 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently num

持之以恒_fighting 601

POJ 3268 Silver Cow Party(spfa)

Silver Cow Party Language: Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30402 Accepted: 13798 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numb...

muyu__的博客 255

poj 3268 Silver Cow Party , spfa , dijkstra

点击打开链接 两次求最短路(第二次把边反向求) 1、spfa //poj 3268 Silver Cow Party //SPFA #include #include #include using namespace std; const int M = 100000 + 100; const int N = 1000 + 100; const int inf = 1

天亮说晚安 1763

poj3268 Silver Cow Party(SPFA)

题目请戳这里 题目大意:n个点,m条边的有向图,给定一个点x,现在要求所有点出发到x再回到各自的点的总路程的最大值。 题目分析:有向图,求来回距离和的最大值。我们可以将这段路程分成2部分:先走到x,再从x到各点。从x回到各点好办,就是一个单源最短路的问题。但是要求从各点到x的距离,可以反过来求,因为是有向图,所以建一个反图,这样从所有点到x就又变成了从x到所有点,又变成了一个单源最短路。所以本

ophunter的专栏 1178

POJ 3268 Silver Cow Party 【单项图,双向spfa】

点击打开链接 题意: 给你一个单项图。然后问你从一个点出发,到其他所有点再回来,花费的最长时间是哪一次。 题解: spfa,或者 DJ  都可以 单元最短路, 因为图是单向的,那么a->b  求一遍之后,  地图换个方向, 再来一遍a->b  。 之和就是来回。两次单源最短路。就解决了 2*n^2,   之前看了一眼,直接想暴力一发floyd。 觉得这个最好用,结果

zoro_n的博客 331

poj 3268 Silver Cow Party(最短路)

poj 3268 Silver Cow PartyDescription One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 1618

Poj 3268 Silver Cow Party【SPFA】

Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17517   Accepted: 8021 Description One cow from each of N farms (1 ≤ N ≤ 1

mengxiang000000 733

SPFA POJ 3268 Silver Cow Party

题目链接:http://poj.org/problem?id=3268 题目大意:有n个位置,m条路,求所有点到某一固定点x往返时间的最大值(有向),从i位置到j位置所需要用的时间 算法:SPFA 思路:2次SPFA,一次正向,第二次反向 #include #include #include #include #include using namespace std; const

ACmood 504

POJ3268 Silver Cow Party SPFA

对图分别建立入边表和出边表,分别求出x到个点的最短路,然后相加求出最大值。 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8756   Accepted: 3911 Descriptio

539

POJ - 3268 Silver Cow Party(Dijkstra,Spfa)

POJ - 3268 Silver Cow Party(Dijkstra) Dijkstra邻接矩阵 #include<iostream> #include<cstring> using namespace std; const int N = 1010; int n,m,x; int g[N][N],rg[N][N],dist[N],rdist[N]; bool st[N]; void dijkstra(int a[N][N],int dist[]) { memset(st,f

00后的博客 614

Silver Cow Party - POJ 3268 spfa

Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13006   Accepted: 5824 Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl

提比的强行AC 560
上一篇: break语句的使用
下一篇: 定义#define
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值