diff --git a/TangDou/Topic/PrefixAndSuffix/P5638.cpp b/TangDou/Topic/PrefixAndSuffix/P5638.cpp new file mode 100644 index 0000000..5150be6 --- /dev/null +++ b/TangDou/Topic/PrefixAndSuffix/P5638.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +const int N = 1000010; +#define int long long +#define endl "\n" +int a[N], s[N]; +int n, k; // n个城市,传送半径为k +signed main() { + cin >> n >> k; // n个城市,传送半径为k + for (int i = 1; i < n; i++) { // 以起点为线段命名的编号,所以1~n共n个城市,其实是n-1条线段 + cin >> a[i]; // 走这条路要耗费时间a[i] + s[i] += s[i - 1] + a[i]; // 前缀和 + } + int ans = s[n - 1]; // sum总和 + // 这是在枚举什么? + for (int i = k; i < n; i++) ans = min(ans, s[n - 1] - (s[i] - s[i - k])); + cout << ans << endl; +} \ No newline at end of file diff --git a/TangDou/Topic/【前缀和与差分】题单.md b/TangDou/Topic/【前缀和与差分】题单.md index b7a484d..9c8bea0 100644 --- a/TangDou/Topic/【前缀和与差分】题单.md +++ b/TangDou/Topic/【前缀和与差分】题单.md @@ -214,6 +214,25 @@ signed main() { #### [$P5638$ 光骓者的荣耀](https://www.luogu.com.cn/problem/P5638) +**题目大意** +用最少时间要将所有城市全部访问完,若有传送器可使用传送器。 + +**坑点** +- 需要考虑传送器数量与城市的数量 ,若传送器大于城市输出$0$ +- 需要考虑数据范围较大,`long long int` + +**数据范围** +开一个大于$10$的$6$次方的数据 + +**思路** +- 先考虑特例 +- 由于需要最短时间,所以在有传送器的情况下使用传送器到最后一个城市 + +利用前缀和,找出可以“省去”的路,相减即可 + + + + #### [$P1719$ 最大加权矩阵](https://www.luogu.com.cn/problem/P3406) #### [$P2004$ 领地选择](https://www.luogu.com.cn/problem/P2004)