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 [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
随机推荐
- JavaWeb之 JSP:自定义标签
当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 自定义标签 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写一个普通的 ...
- hdu 4613 Points<计算几何>
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4613 题意: 判断一个集合中的点能不能由另一个集合中的点,通过平移,旋转,放缩得到~ 思路:先求出集合中的 ...
- esp和ebp详解
最近在研究栈帧的结构,但总是有点乱,所以写了一个小程序来看看esp和ebp在栈帧中的作用.这个程序如下: 这个程序很简单,就是求两个数的值,然后输出即可.所以首先把它用gcc编译链接成a.out,进入 ...
- hdu 1412 {A} + {B}
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 {A} + {B} Description 给你两个集合,要求{A} + {B}.注:同一个集合 ...
- 关于Filezilla是否支持sftp
我们知道filezilla是一个开源的ftp的解决方案,它提供了客户端和服务器端,支持的fpt, sftp, ftps,这是你可以从wiki中看到的关于filezilla的介绍,但是这里需要澄清一点就 ...
- c/c++常用代码--使用libcurl下载文件
#pragma once #include <stdio.h>#include <stdlib.h> #include <curl/curl.h> #ifdef ...
- Some Tips About VS2015
Xaml edit bug about vs2013+ sometimes, vs will say some class not found in the namespace. but, we co ...
- C# 字符串详细使用
转自 http://www.cnblogs.com/candywyq/archive/2007/07/24/830021.html 1.Convert.ToInt32与Int32.Parse的恩恩怨怨 ...
- Ubuntu 12.04 Desktop安装XAMPP
1/打开终端 在Dash里搜索.打开Dash,在里面搜索“gnome-terminal”,就可以找到终端应用序.快捷键Ctrl+Alt+L也可以,不过如果是虚拟机的话可能会有问题. 如果想以后快捷打开 ...
- 通过修改注册表来破解sqlyog
Sqlyog作为一款可视化的数据库管理工具,各种方便我就不说了,但是未经汉化或者绿色过的软件存在30天的生命期,到期后我们就不可以使用了,要摸卸载重装,我们还可以去修改注册表,来延长它的生命期,具体步 ...