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

[COCI2022-2023#2] Tramvaji 题解

简要题意

告诉一些站点之间的距离,求两站距离最小的两个站

思路

对于某个站点,站台1到他前面的站的距离一定已经处理好了,所以可以用一个数组维护前缀和,从前面某个站转移过来,最后统计就行了

Code:

#include <bits/stdc++.h>
using namespace std;
namespace IO{inline long long read() {long long res = 0; bool f = 0;char ch = getchar();while (ch < '0' || ch > '9')f |= (ch == '-'), ch = getchar();while (ch >= '0' && ch <= '9')res = (res << 3) + (res << 1) + ch - '0', ch = getchar();return f ? -res : res;}
}
using IO::read;
const int MAXN = 1e3 + 5;
int dist[MAXN];
int n;
int main() {// freopen("tramvaji.in", "r", stdin);// freopen("tramvaji.out", "w", stdout);n = read();for (int i = 2; i <= n; ++i) {string s;int y, t;cin >> s;if (s == "Patrik") {t = read();dist[i] = t;}else if (s == "Josip") { y = read(), t = read();dist[i] = dist[y] + t;}}int min_time = 0x3f3f3f3f, s = 0;for (int i = 2; i <= n; ++i) {if (dist[i] - dist[i - 1] < min_time)min_time = dist[i] - dist[i - 1], s = i - 1;}// cerr << dist[3][4];cout << min_time << ' ' << s << ' ' << s + 1;return 0;
}
http://www.jsqmd.com/news/14357/

相关文章:

  • 一级指针和二级指针作为函数参数的区别
  • ROUGE指标
  • CSP-S 模拟 29
  • 实用指南:【编号508】(道路分类)湖南路网数据湖南路网分类数据(2025年)
  • Linux 文件及相关安全操作指南
  • day012
  • 怎么能把一个横着的很长的excel表,输出成一个能完整展示在一个页面中的PDF
  • agent技术框架
  • agent策略分析与Parer解读
  • 夸克网盘免费扩容,新用户轻松领取1TB免费空间!一步一步教你如何操作! - 详解
  • Visual Studio 2022连接mysql数据库,解决System.Data.Odbc.OdbcException (0x80131937)
  • [AI生成]Spark-TTS个人理解
  • 2025.10.3 测试
  • [20251015]建立和完善col_vlist.sql脚本.txt
  • [20251014]建立完善通用的prx.sql脚本.txt
  • 倍增法
  • 征程 6 | BPU trace 简介与实操
  • 实验任务2
  • 牛客2025秋季算法编程训练联赛1
  • 2025 年风淋室厂家选哪家?广州灵洁凭技术专利与全链服务打造净化设备优质之选
  • 251015读书报告
  • JAVA8 map flatmap用法
  • Spring bean初始化过程
  • 吴恩达深度学习课程一:神经网络和深度学习 第二周:神经网络基础 课后习题和代码实践
  • 【Windows】如何管理电脑磁盘文件,保持简洁 - 教程
  • 范围综述
  • CSP-S模拟30
  • 2025多校冲刺CSP模拟赛5
  • 应用安全 --- 安卓神器 之 入口加密
  • float