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 ;
}

最新文章

  1. ZOJ Problem Set - 1001 A + B Problem
  2. 2016年iOS技术圈回顾
  3. HTML5 直播协议之 WebSocket 和 MSE
  4. String与StringBuffer的区别
  5. C++ 迭代器 基础介绍
  6. oracle 自定义聚合函数(MAX_O3_8HOUR_ND) 计算最大的臭氧8小时滑动平均值
  7. LevelDB:一个快速轻量级的key-value存储库(译)
  8. 初步认知MySQL metadata lock(MDL)
  9. 【搜索引擎Jediael开发笔记】v0.1完整代码
  10. The required anti-forgery form field &quot;__RequestVerificationToken&quot; is not present.
  11. SonarQube和Maven的集成
  12. POJ-3421 X-factor Chains---求因子+递推 或 素因子+组合数学
  13. Game Engine Architecture 2
  14. BSOJ 4591 -- 【JLOI2015】城池攻占
  15. Notepad++ 中使用tail -f功能
  16. Qt 的线程与事件循环
  17. (转载)UTF-8和GBK的编码方式的部分知识:重要
  18. canvas设置repeat
  19. isset()、empty()、is_NULL()的区别
  20. 64位WIN7上安装11G R2 ,PLSQL的配置方法

热门文章

  1. 要提高SQL查询效率where语句条件的先后次序应如何写
  2. RESET MASTER和RESET SLAVE使用场景和说明
  3. lsync目录文件实时同步工具
  4. Spring+微信小程序 卡券打通
  5. JdkDynamicAopProxy-笔记
  6. js(window.open)浏览器弹框居中显示
  7. 微信小程序 置顶/取消置顶
  8. java基础集合类——ArrayList 源码略读
  9. Spring源码分析(十四)从bean的实例中获取对象
  10. ZOJ 3212 K-Nice(满足某个要求的矩阵构造)