题目

感谢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(有深度的模拟)的更多相关文章

  1. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  3. Codeforces 442C Artem and Array (看题解)

    Artem and Array 经过分析我们能发现, 如果对于一个a[ i ] <= a[ i + 1 ] && a[ i ] <= a[ i - 1 ]可以直接删掉. 最 ...

  4. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

  5. cf442C Artem and Array

    C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  7. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

  8. Codeforces 442C

    题目链接 C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

随机推荐

  1. HelloWorld IL代码

    .assembly extern mscorlib .assembly HelloWorld.class HelloWorld extends [mscorlib] System.Object {   ...

  2. Microsoft Visual Studio 语言切换

    事情的起因是需要安装本地的中文帮助,OS以及Viusal Studio都安装的英语版本. 其实需要安装的安装Viusal Studio的中文语言包即可. 通过工具选项可以达到以下的对话框 可以通过下载 ...

  3. String类详解,StringBuffer

    先说一下String类的equals()方法. 下面我们先看一段代码: 这段代码输出的结果为: ture true -------------- false 咋看之下貌似Object类比较特别,那么我 ...

  4. Android--WebView的一些配置项

    //打开页面时,自适应屏幕 wv_showWeb_webActivity.getSettings().setUseWideViewPort(true);//设置此属性可以任意比例缩放 wv_showW ...

  5. ListView的多布局中的小问题

    今天用到了ListView的多布局,我们需要额外重写两个方法 //返回多布局的个数 @Override public int getViewTypeCount() { return 3; } //用该 ...

  6. 禁用DropDownList的Items

    可以先看看效果,被禁用的DropDownList的Items已经无法选取与颜色也变为灰色. 刚开始,DropDownList没有接收从网址传来的参数时,它每一个Item都是可以选取的,一旦接收了值.所 ...

  7. ios开发--常用宏定义(部分转)

    1.release时,屏蔽log #if defined (DEBUG) && DEBUG == 1 #else #define NSLog(...) {}; #endif #if d ...

  8. C#泛型集合之Dictionary<k, v>使用技巧

    1.要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) 2.描述 1).从一组键(Key)到一组值(Value) ...

  9. 关于使用,NI采集卡+labview信号采集,问题交流【第二贴】

    *** 采集卡 NI PCI-6534:  max sample rate 20MHz:32位的数字输入,数字输出.  ***输入信号:    峰峰值,4.16V   最小值 -80mV    频率 ...

  10. Ant学习---第一节:Ant安装和简单使用

    一.下载 ant 插件,路径如下: http://ant.apache.org/bindownload.cgi 二.安装 ant 插件,解压下载下来的 ant 插件,配置环境变量(最好系统环境变量), ...