当前位置: 首页 > news >正文

牛客 NC24858 [USACO 2009 Nov S]Job Hunt

题目描述

Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make D (1 <= D <= 1,000) dollars in a city before they must work in another city. Bessie can, however, return to a city after working elsewhere for a while and again earn the D dollars maximum in that city. There is no limit on the number of times Bessie can do this.
Bessie's world comprises P (1 <= P <= 150) one-way paths connecting C (2 <= C <= 220) cities conveniently numbered 1..C. Bessie is currently in city S (1 <= S <= C). Path i runs one-way from city Ai to city Bi (1 <= Ai <= C; 1 <= Bi <= C) and costs nothing to traverse.
To help Bessie, Farmer John will give her access to his private jet service. This service features F (1 <= F <= 350) routes, each of which is a one way flight from one city Ji to a another Ki (1 <= Ji <= C; 1 <= Ki <= C) and which costs Ti (1 <= Ti <= 50,000) dollars. Bessie can pay for the tickets from future earnings if she doesn't have the cash on hand.
Bessie can opt to retire whenever and wherever she wants. Given an unlimited amount of time, what is the most money that Bessie can make presuming she can make the full D dollars in each city she can travel to? Print -1 if there is no limit to this amount.

输入描述:

* Line 1: Five space-separated integers: D, P, C, F, and S
* Lines 2..P+1: Line i+1 contains two space-separated integers that name a one-way path from one city to another: Ai and Bi
* Lines P+2..P+F+1: Line P+i+1 contains three space-separated integers that name a one-way jet flight from one city to another and the price for that flight: Ji, Ki, and Ti

输出描述:

* Line 1: A single integer representing the most money she can make while following the law.

示例1

输入

复制

100 3 5 2 1
1 5
2 3
1 4
5 2 150
2 5 120

输出

复制

250

说明

This world has five cities, three paths and two jet routes. Bessie starts out in city 1, and she can only make 100 dollars in each city before moving on.
Bessie can travel from city 1 to city 5 to city 2 to city 3, and make a total of 4*100 - 150 = 250 dollars.

思路:这是一道比较裸的最长路问题,只要将起点的距离初始化为d,建图时两点之间的路径距离为d,航线距离为d-c;

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;

const int N=230,M=100010;

int h[N],ne[M],e[M],w[M],idx;
int d,m,n,f,s;
int dist[N];
bool st[N];

void add(int a,int b,int c)
{
	e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}

void spfa()
{
	memset(dist,-0x3f,sizeof dist);
	queue<int> q;
	dist[s]=d;
	q.push(s);
	
	while(q.size())
	{
		int t=q.front();
		q.pop();
		st[t]=0;
		
		for(int i=h[t];~i;i=ne[i])
		{
			int j=e[i];
			if(dist[j]<dist[t]+w[i])
			{
				dist[j]=dist[t]+w[i];
				if(!st[j])
				{
					q.push(j);
					st[j]=1;
				}
			}
		}
	}
}

int main()
{
	memset(h,-1,sizeof h);
	scanf("%d%d%d%d%d",&d,&m,&n,&f,&s);
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		add(a,b,d);
	}
	while(f--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		add(a,b,d-c);
	}
	
	spfa();
	
	int res=-0x3f3f3f3f;
	for(int i=1;i<=n;i++)
		res=max(res,dist[i]);
	cout<<res;
}

相关文章:

  • 687 最长同值路径——Leetcode 天天刷(2022.9.2)【DFS】
  • 新店速递丨白玉兰(商务)酒店赣榆吾悦广场店 正式上线
  • Windows 10 安装 Redis
  • java基于springboot+vue+elementui的漫画投稿交流平台 前后端分离
  • Tomcat服务部署,虚拟主机配置,
  • 支持向量机
  • R Markdown 格式
  • Opncv 实现拍照、颜色识别和阈值选取
  • 计算机网络——网络协议
  • 对回调函数和消息机制的理解
  • 关于voreen编译的一些问题
  • 树莓派——9、IO操控代码编程
  • springboot+新冠疫苗预约管理系统 毕业设计-附源码241530
  • Dubbo注册中心
  • 【模型篇】01 记点脑子里还残存的关于模型分类的三种方式
  • 2019.2.20 c++ 知识梳理
  • C学习-枚举(九)
  • docker-consul
  • download使用浅析
  • E-HPC支持多队列管理和自动伸缩
  • HashMap剖析之内部结构
  • MQ框架的比较
  • Redux 中间件分析
  • 成为一名优秀的Developer的书单
  • 初探 Vue 生命周期和钩子函数
  • 简单数学运算程序(不定期更新)
  • 解析 Webpack中import、require、按需加载的执行过程
  • ​sqlite3 --- SQLite 数据库 DB-API 2.0 接口模块​
  • ​力扣解法汇总1802. 有界数组中指定下标处的最大值
  • # 20155222 2016-2017-2 《Java程序设计》第5周学习总结
  • #git 撤消对文件的更改
  • #Z2294. 打印树的直径
  • ()、[]、{}、(())、[[]]命令替换
  • (delphi11最新学习资料) Object Pascal 学习笔记---第2章第五节(日期和时间)
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (十三)Java springcloud B2B2C o2o多用户商城 springcloud架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)...
  • (万字长文)Spring的核心知识尽揽其中
  • (原创)Stanford Machine Learning (by Andrew NG) --- (week 9) Anomaly DetectionRecommender Systems...
  • (转)关于多人操作数据的处理策略
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • (转载)Linux 多线程条件变量同步
  • .gitignore
  • .NET Core 中的路径问题
  • .NET core 自定义过滤器 Filter 实现webapi RestFul 统一接口数据返回格式
  • .net 发送邮件
  • .net 反编译_.net反编译的相关问题
  • .NET/C# 如何获取当前进程的 CPU 和内存占用?如何获取全局 CPU 和内存占用?
  • .net6使用Sejil可视化日志
  • .NET成年了,然后呢?
  • .net打印*三角形
  • .NET框架
  • .net知识和学习方法系列(二十一)CLR-枚举
  • .NET值类型变量“活”在哪?
  • ::