AGC 030 B - Tree Burning
2024-10-15 07:50:22
B - Tree Burning
题意:
一个长度为L的环,有n个位置上有树,从0出发,每次选择一个方向(顺时针或者逆时针),一直走,直到走到一棵树的位置,烧掉这棵树,重复这个过程,直到没有树。求最多走多少距离。
分析:
最优一定是LLLRLRLRL……类似这样的,于是枚举每个点,计算答案。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; LL s1[N], s2[N], a[N], L, Ans;
int n; LL f(int l,int r) {
return s1[r] - a[l] * (r - l) - s1[l];
} void Calc() {
for (int i = ; i <= n; ++i)
s1[i] = s1[i - ] + a[i], s2[i] = s2[i - ] + (L - a[n - i + ]);
for (int i = ; i < n; ++i) {
LL now = a[i] * (n - i) + a[i];
int cnt = (n - i) / ;
if ((n - i) % == )
now += s2[cnt] * + f(i, i + cnt) * - (a[i + cnt] - a[i]);
else
now += s2[cnt + ] * + f(i, i + cnt) * - (L - a[n - cnt]);
Ans = max(Ans, now);
}
}
int main() {
L = read(); n = read();
for (int i = ; i <= n; ++i) a[i] = read();
Calc();
for (int i = ; i <= n; ++i) a[i] = L - a[i];
reverse(a + , a + n + );
Calc();
cout << Ans;
return ;
}
最新文章
- ZOJ Problem Set - 1001 A + B Problem
- 2016年iOS技术圈回顾
- HTML5 直播协议之 WebSocket 和 MSE
- String与StringBuffer的区别
- C++ 迭代器 基础介绍
- oracle 自定义聚合函数(MAX_O3_8HOUR_ND) 计算最大的臭氧8小时滑动平均值
- LevelDB:一个快速轻量级的key-value存储库(译)
- 初步认知MySQL metadata lock(MDL)
- 【搜索引擎Jediael开发笔记】v0.1完整代码
- The required anti-forgery form field ";__RequestVerificationToken"; is not present.
- SonarQube和Maven的集成
- POJ-3421 X-factor Chains---求因子+递推 或 素因子+组合数学
- Game Engine Architecture 2
- BSOJ 4591 -- 【JLOI2015】城池攻占
- Notepad++ 中使用tail -f功能
- Qt 的线程与事件循环
- (转载)UTF-8和GBK的编码方式的部分知识:重要
- canvas设置repeat
- isset()、empty()、is_NULL()的区别
- 64位WIN7上安装11G R2 ,PLSQL的配置方法