[CF846C]Four Segments题解
我们暴力枚举一下\(delim_{1}\)
然后对于每个\(delim_{1}\),O(n)扫一遍+前缀和求出最大\(delim_{0}\)和\(delim_{2}\),然后记录一下它们的位置就行啦
放个代码
#include <cstdio>
#define ll long long
inline ll read(){
ll x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
long long qzh[5005];
int main(){
int n = read();
for (int i = 1; i <= n; ++i)
qzh[i] = read();
for (int i = 1; i <= n; ++i)
qzh[i] += qzh[i - 1];
long long cur1, cur2, ans = 0;
int pos1, pos3, p1 = 0, p2 = 0, p3 = 0;
for (int i = 0; i <= n; ++i){
cur1 = cur2 = 0;
pos1 = 0, pos3 = i;
for (int j = 0; j <= i; ++j)
if (qzh[j] - (qzh[i] - qzh[j]) > cur1){
cur1 = qzh[j] - (qzh[i] - qzh[j]);
pos1 = j;
}
for (int j = i; j <= n; ++j)
if ((qzh[j] - qzh[i]) - (qzh[n] - qzh[j]) > cur2){
cur2 = (qzh[j] - qzh[i]) - (qzh[n] - qzh[j]);
pos3 = j;
}
if (cur1 + cur2 > ans){
ans = cur1 + cur2;
p1 = pos1;
p2 = i;
p3 = pos3;
}
}
printf("%d %d %d", p1, p2, p3);
return 0;
}
[CF846C]Four Segments题解的更多相关文章
- POJ3304:Segments——题解
http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ——————————————————————— ...
- Codeforces Round #535(div 3) 简要题解
Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...
- Codeforces Round #690 (Div. 3)
第一次 ak cf 的正式比赛,不正式的是寒假里 div4 的 Testing Round,好啦好啦不要问我为什么没有 ak div4 了,差一题差一题 =.= 不知不觉已经咕了一个月了2333. 比 ...
- 题解-CF1389F Bicolored Segments
题面 CF1389F Bicolored Segments 给 \(n\) 条线段 \([l_i,r_i]\),每条有个颜色 \(t_i\in\{0,1\}\),求最多选出多少条线段,使没有不同颜色的 ...
- CodeForces 430A Points and Segments (easy)(构造)题解
题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序 ...
- LeetCode题解之Number of Segments in a String
1.题目描述 2.题目分析 找到字符串中的空格即可 3.代码 int countSegments(string s) { ){ ; } vector<string> v; ; i < ...
- PAT甲题题解-1104. Sum of Number Segments (20)-(水题)
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【题解】CF1426D Non-zero Segments
题目戳我 \(\text{Solution:}\) 若\([l,r]\)子段和是\(0,\)则\(sum[r]=sum[l-1].\) 于是我们可以考虑维护当前哪一个前缀和出现过.对于区间\([l,r ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
随机推荐
- CDN分发
CDN 是Content Delivery Network,即内容分发网络. 未完待续..
- sorted()与sort()函数
1 sorted可以对series,ndarry,list类型进行排序 默认会从小到大进行排序 arr1 = np.array([1,2,3,4,44,3243,43,8678]) print(sor ...
- 【ABAP系列】SAP ABAP 仓库库存-物料拆分的算法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 仓库库存-物料 ...
- 一些输出、处理细节&注意点
https://blog.csdn.net/qq_41071646/article/details/79953476 输出百分比的时候,结果需要加上一个EPS(1e-6)四舍五入保证精度. 卡精度—— ...
- IDEA常用快揵键
IDEA常用快揵键 工作中常用IDEA快捷键 参见博客:https://www.cnblogs.com/zhangpengshou/p/5366413.html Double shift --- ...
- Java基础/利用fastjson序列化对象为JSON
利用fastjson序列化对象为JSON 参考博客:http://blog.csdn.net/zeuskingzb/article/details/17468079 Step1:定义实体类 //用户类 ...
- linux 简单安装mongodb
Linux 安装mongodb 1.下载mongodb linux wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon- ...
- springboot启动时报错 错误: 找不到或无法加载主类 com.xxx.xxx.Application
1. Q1 错误: 找不到或无法加载主类 com.xxx.xxx.Application 解决办法:啥也不动,maven clean下,重启 1. Q2 layui控制下拉框高度 解决 .layui- ...
- vs2015上编译QT程序的环境搭建
下载相对应版本的QT(以QT5.7.0为例),进入网站http://download.qt.io/archive/qt/5.7/5.7.0/,下载MSVC版本QT,我的系统是64位,VS版本是2015 ...
- Js中className的用法
className可以用来改变标签元素的css类选择器,从而改变元素的样式 举个栗子 一个简单的无序列表,点击button之前ul的样式为uhh1 点击button后,调用check函数中的class ...