跳到正文

题解

P5638 【CSGRound2】光骓者的荣耀题解

leemavis约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年10月28日
篇幅
约 1 分钟
获赞
1

版本

  1. v1当前

嗯对大概就是学到前缀和和数论了吧,训练有这道题,干脆就写个题解吧

反正也没人看

题目传送门:https://www.luogu.com.cn/problem/P5638

题目大概讲的就是

线性城市网络的最优传送策略:通过前缀和计算跳过最长k段路径的最小总用时

题目看着很抽象但其实只是考察我们对前缀和的概念的掌握 总之很简单就对了

AC代码

C++
#include<bits/stdc++.h>
using namespace std;
long long a[1000005],sum[1000005];
int main(){
	long long n,k,total=0,maxx=0;
	cin>>n>>k;
	for(int i=1;i<n;i++){
		cin>>a[i];
		total+=a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=k;i<n;i++){//半径为k的传送器 i-k
		long long temp=sum[i]-sum[i-k];// sum[i] 表示从城市 1 走到城市 i+1 的总时间
		if(temp>maxx) maxx=temp;//maxx 记录所有可能的 k 连续路段中的最大总时间
	}
	cout<<total-maxx;//使用传送器后的最短时间。
	return 0;
}

真的不难 蒟蒻萌新求赞谢谢各位了<。)#)))≦

原文