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 [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
随机推荐
- python35
在计算机内存中,统一使用Unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为UTF-8编码.Python对bytes类型的数据用带b前缀的单引号或双引号表示x = b'ABC' //每个字 ...
- C# 添加一个用户对文件或者文件夹的所有权限
private void ModifyFilePermission(string path, string user, FileType filetype) { if (filetype == Fil ...
- Linux基础 30分钟GDB调试快速突破
引言 Linus心灵鸡汤 在*nix开发中有道卡叫gdb调试,不管你怎么搞. 它依然在那丝毫不会松动.今天致敬一个 活着的传奇 Linus Torvalds Unix 始于上个世纪60年代,在70年代 ...
- SOCKET 地址
地址格式: 函数bind和getsockname使用通用数据类型:struct sockaddr*来指向socket地址. #incude <sys/socket.h> struct so ...
- CSV 文件读取类
class CsvReader { private $csv_file; private $spl_object = null; private $error; public function __c ...
- Windows Phone 8.1SDK新特性预览
前言 Windows Phone 8.1的预览版将在近期推送,WP 8.1的SDK也已经进入到RC阶段,可以从这里安装.本次更新的SDK被直接集成到了VS2013Update2里面,不再是单独的 ...
- EF6 在原有数据库中使用 CodeFirst 总复习(三、重建迁移)
本来原来学的时候,挺顺利的,没想到再次使用,还是遇到很多问题,导致更新失败,所以,只能重建迁移,免得看着乱乱的. 一.删除迁移,将数据恢复到(一)结束状态 1.删除文件夹 2.删除表 3.删除列 4. ...
- Win8.1+vs2012+osg环境搭建
Win8.1+vs2012+osg环境搭建 一. 相关准备 a) Osg源码 当前最新版:OpenSceneGraph-3.2.0.zip 下载链接: http://www.opensceneg ...
- 【上传AppStore】iOS项目上传到AppStore步骤流程(第三章) - 基本信息总汇
一.App ID(bundle identifier) App ID即Product ID,用于标识一个或者一组App. App ID应该和Xcode中的Bundle Identifier是一致(Ex ...
- Careercup - Microsoft面试题 - 5673934611546112
2014-05-10 23:26 题目链接 原题: what is the best,worst and average case complexity for fibonacci no.s ..ex ...