codeforces 442C C. Artem and Array(有深度的模拟)
感谢JLGG的指导!
思路:
//把数据转换成一条折线,发现有凸有凹
//有凹点,去掉并加上两边的最小值
//无凹点,直接加上前(n-2)个的和(升序)
//数据太大,要64位
//判断凹与否,若一边等于,一边大于,那中间这个也算是凹进去的,所以判断时要加上等于
//有凹点,去掉并加上两边的最小值
//无凹点,直接加上前(n-2)个的和(升序)
//数据太大,要64位
//判断凹与否,若一边等于,一边大于,那中间这个也算是凹进去的,所以判断时要加上等于 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
int n,a[],b[];
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
ll ans=;
if(n>)
{
int id=;
b[id++]=a[];
b[id++]=a[];
for(int i=;i<n;i++)
{
while(b[id-]<=b[id-]&&b[id-]<=a[i])//难道是因为没有等于的缘故
{
ans+=min(b[id-],a[i]);
id--;
}
b[id++]=a[i];
}
sort(b,b+id);
for(int i=;i<id-;i++)
ans+=b[i];
}
printf("%I64d\n",ans);
}
return ;
}
codeforces 442C C. Artem and Array(有深度的模拟)的更多相关文章
- codeforces 442C C. Artem and Array(贪心)
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces 442C Artem and Array (看题解)
Artem and Array 经过分析我们能发现, 如果对于一个a[ i ] <= a[ i + 1 ] && a[ i ] <= a[ i - 1 ]可以直接删掉. 最 ...
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- cf442C Artem and Array
C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- [Codeforces 266E]More Queries to Array...(线段树+二项式定理)
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...
- Codeforces 442C
题目链接 C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【Codeforces 258B】 Sort the Array
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
随机推荐
- 《高性能javascript》读书笔记
1.每个<script>加载时都会阻塞其他文件(图片.音乐等)的同时加载,同时浏览器会在js代码执行时停止渲染Dom.所以为了减少界面加载的卡顿和空白发生,应尽力将js代码或者文件放在&l ...
- ubuntu 14.04 下安装jdk8及 smartgithg
公司使用git作为源码管理,又需要在ubuntu下工作,然后,自己就找了找,目前ubuntu下的git gui客户端,感觉 smartgit算是其中比较好用的一个,下边是具体安装步骤 说明,smart ...
- openSUSE13.2安装ruby和rails
用rvm安装了ruby2.2.0之后,发现rails又装不了了,因为什么nokgiri安不上需要安装两个包: libxml2 libxml2-dev libxslt libxslt-dev 然后gem ...
- WPF:将HTML RGB颜色值转化为Color对象的两种方式
(1)方式一: Color color1 = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#E0E0E0&qu ...
- “猜你喜欢”是怎么猜中你心思的?
文/Joseph A. Konstan & John Riedl)如今,到网上购物的人已经习惯了收到系统为他们做出的个性化推荐.Netflix 会推荐你可能会喜欢看的视频.TiVo 会自动把节 ...
- strcpy/strlen/strcat/strcmp面试总结
<strcpy拷贝越界问题> 一. 程序一 #include<stdio.h> #include<string.h> void main() { char s[]= ...
- hdu 5412 CRB and Queries
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5412 CRB and Queries Description There are $N$ boys i ...
- iOS学习之C语言结构体
结构体:用来存放相同类型数据或者不同类型数据的自定义类型. 结构体定义(声明) struct 结构体名 { 成员变量1; 成员变量2; ... }; typedef 现有类型 新的类 ...
- 低噪声APD偏置电路
低噪声APD偏置电路 APD电源摘要:该电路产生并控制光通信中雪崩光电二极管(APD)的低噪声偏置电压.该可变电压通过控制APD的雪崩增益,优化光纤接收器的灵敏度特性.该电路采用低噪声.固定频率PWM ...
- 程序开发心理学阅读笔记——第I篇
1.软件的任务是为了解决某一特定的问题,而软件开发者的任务却需要解决一系列问题.2.温伯格说,我们不能要求每个人都聪明异常,能够解决所有难题:但是我们必须持续思考,因为只有如此,我们才能明白自己在做什 ...