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

AGC 030 B - Tree Burning的更多相关文章

  1. AGC 030 B - Tree Burning 结论+枚举

    考试 T2,是一个脑筋急转弯. 最暴力的贪心是每次先选左,再选右,再选左..... 然而这么做在一些情况下是错的. 但是,我们发现我们的选法一定是 $LLLLRLRLRLRLR$ 或 $RRRRLRL ...

  2. AGC 030B.Tree Burning(贪心)

    题目链接 \(Description\) 有一个长为\(L\)的环,上面有\(n\)棵树,坐标分别为\(a_i\).初始时在原点. 每次你可以选择顺时针或逆时针走到第一棵没有被烧掉的树,停在这个位置, ...

  3. AtCoder AGC030B Tree Burning

    题目链接 https://atcoder.jp/contests/agc030/tasks/agc030_b 题解 细节好题.. 首先假设第一步往右走,那么可以发现当拐弯的次数一定时路径是唯一的 于是 ...

  4. AtCoder Grand Contest 030题解

    第一次套刷AtCoder 体验良好 传送门 Poisonous Cookies cout<<b+min(c,a+b+); Tree Burning 难度跨度有点大啊 可以证明当第一次转向之 ...

  5. AtCoder Grand Contest 030 Solution

    A - Poisonous Cookies 签到. #include <bits/stdc++.h> using namespace std; #define ll long long l ...

  6. [Agc030B]Tree Burning_贪心

    Tree Burning 题目链接:https://atcoder.jp/contests/agc030/tasks/agc030_b 数据范围:略. 题解: 开始以为是左右左右这样,发现过不去样例. ...

  7. AtCoder练习

    1. 3721 Smuggling Marbles 大意: 给定$n+1$节点树, $0$为根节点, 初始在一些节点放一个石子, 然后按顺序进行如下操作. 若$0$节点有石子, 则移入盒子 所有石子移 ...

  8. AGC030 简要题解

    A - Poisonous Cookies 题意 有\(A\)个能解毒的普通饼干,\(B\)个能解毒的美味饼干,\(C\)个有毒的美味饼干,求最多能吃多少个美味饼干,每次吃完有毒的饼干后要解毒后才能继 ...

  9. 【AtCoder】AGC030

    A - Poisonous Cookies 有毒还吃,有毒吧 #include <bits/stdc++.h> #define fi first #define se second #de ...

随机推荐

  1. 连接AWS Ubuntu服务器

    1.在AWS上创建了Ubuntu实例后,在实例里点连接.点使用PuTTY连接,下载PuTTY软件. 2.在所有程序里找到PuTTYgen并打开,点Load选择创建实例时的pem文件,点save pri ...

  2. 转:HTTP Status 404(The requested resource is not available)的几种解决方法

    原文地址 原因:servlet没有配置正确 ,查看web.xml确认正确,以及自己的请求路径正确 在IE中提示“404”错误有以下三种情况 1.未部署Web应用 2.URL输入错误 排错方法: 首先, ...

  3. include方便查找

    #include <assert.h> //设定插入点#include <ctype.h> //字符处理#include <errno.h> //定义错误码#inc ...

  4. matlab 函数句柄@的介绍_什么是函数句柄(转)

    http://blog.csdn.net/kevinhg/article/details/8861774 http://www.ilovematlab.cn/thread-30375-1-1.html ...

  5. D:\hunting2014\小题目\字符串倒序

    #include<stdio.h>#include<string.h> char *revert(char *str){ char temp; char *p = str; c ...

  6. map filter 的func 放在前面

    map    filter      的func 放在前面 sorted 在后 (    iter..  ,       key=function')

  7. GIT非常见命令使用笔记

    1:修改已经提交N次代码的user.name和user.email 解决我在多电脑间,使用不同账户,git config 的global,system,local配置忽略改动,而添加了多台电脑ssh ...

  8. JavaScript实现限时抢购实例

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. 20145203盖泽双 《Java程序设计》第7周学习总结

    20145203盖泽双 <Java程序设计>第7周学习总结 教材学习内容总结 1.如果使用JDK8的话,可以使用Lambda特性去除重复的信息. 2.在只有Lambda表达式的情况下,参数 ...

  10. C语言程序设计I—第七周教学

    第七周教学总结(14/10-20/10) 教学内容 第二章 用C语言编写程序 2.5 生成乘方表和阶乘表 课前准备 在蓝墨云班课发布资源: PTA:2018秋第七周作业 分享码:FE065DC5D8C ...