A题  Price List

巨水..........水的不敢相信。

#include <cstdio>
typedef long long LL;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m,x;
        scanf("%d%d",&n,&m);
        LL sum = ;
        ; i < n; i++)
        {
            int x;
            scanf("%d",&x);
            sum = sum + (LL)x;
        }
        ; i < n; i++)
        {
            LL x;
            scanf("%lld",&x);
            if(x > sum)
                printf(");
            else
                printf(");
        }
        printf("\n");
    }
    ;
}

B题  NanoApe Loves Sequence

这道题可以用线段树做,查询最大值,每次删掉一个点,等于单点更新一到两个点。之后复原一下即可。

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
#define mem0(x) memset(x,0,sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1

 + ];
LL MAX[ << ];
int t;

] , MAX[rt <<  | ]);}
void build(int l,int r,int rt)
{
    ] - a[l]); return ;}
    ;
    build(lson);
    build(rson);
    pushup(rt);
}
void update(int p,int add,int l,int r,int rt)
{
    if(l == r) {t = MAX[rt]; MAX[rt] = add; return ;}
    ;
    if(p <= m)
        update(p,add,lson);
    else
        update(p,add,rson);
    pushup(rt);
}
LL query_max(int ll,int rr,int l,int r,int rt)
{
    if(ll <= l && rr >= r) return MAX[rt];
    LL ans = ;
    ;
    if(ll <= m)
        ans = max(ans,query_max(ll,rr,lson));
    if(rr > m)
        ans = max(ans,query_max(ll,rr,rson));
    return ans;
}
int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        mem0(a);
        mem0(MAX);
        scanf("%d",&n);
        ; i <= n; i++)
        {
            scanf("%d",&a[i]);
        }
        build(,n-,);

        LL ans = ;

        ; i <= n; i++)
        {
            int t1,t2;

             && i != n)
            {
                update(i,abs(a[i+]-a[i-]),,n-,),t1 = t;
                update(i-,abs(a[i+]-a[i-]),,n-,),t2 = t;
            }
            else
            {
                if(i != n)
                    update(i,,,n-,),t1 = t;
                )
                    update(i-,,,n-,),t2 = t;
            }

            ans = ans + query_max(,n-,,n-,);

             && i != n)
            {
                update(i,t1,,n-,);
                update(i-,t2,,n-,);
            }
            else
            {
                if(i != n)
                    update(i,t1,,n-,);
                )
                    update(i-,t2,,n-,);
            }
        }
        printf("%I64d\n",ans);
    }
    ;
}

但是这道题的正解是O(n)的算法。不是线段树。

真的感觉 被 虐智商。人家五分钟搞定这道题= =。

 #include <cstdio>
 #include <cmath>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
  + ;
 int a[maxn], r_max[maxn], l_max[maxn];
 int main()
 {
     int T,n;
     LL ans;
     scanf("%d",&T);
     while(T--)
     {
         scanf("%d",&n);
         ; i <= n; i++)
         {
             scanf("%d",&a[i]);
         }
         l_max[] = ;
         ; i <= n; i++)
         {//r_max 从左边开始到i的最大值
             l_max[i] = max(l_max[i-], abs(a[i] - a[i-]));
         }
         r_max[n] = ;
         ; i >= ; i--)
         {//l_max 从右边开始到i的最大值
             r_max[i] = max(r_max[i+], abs(a[i+] - a[i]));
         }
         ans = (LL) l_max[n-] + (LL) r_max[];
         ; i < n; i++)
         {
             ans = ans + (LL) max(l_max[i-], max(r_max[i+], abs(a[i-] - a[i+]) ) );
         }
         printf("%I64d\n",ans);
     }
     ;
 }

C题  NanoApe Loves Sequence Ⅱ

多少个区间里的第k大的数不小于 m。其实就是说如果这个区间里面能找到,k个大于等于m的数,那么这个区间肯定就满足条件,后面的就不需要管了。

尺取法!!!!

 #include <cstdio>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
  + ];
 bool cmp(int a,int b)
 {
     return a>b;
 }
 int main()
 {
     int T,n,m,k;
     scanf("%d",&T);
     ; i < T; i++)
     {
         scanf("%d%d%d",&n,&m,&k);
         ; i <= n; i++)
             scanf("%d",&a[i]);
         ;
         LL ans = ;
         ;
         ; i <= n; i++)
         {
             while(cnt < k && r < n)
             {
                 r++;
                 cnt += (a[r] >= m);
             }
             if(cnt < k) break;
             ans = ans + (LL) n - r + ;
             cnt -= (a[i] >= m);
         }
         printf("%I64d\n",ans);
     }
     ;
 }

D题

BestCoder Round #86的更多相关文章

  1. [HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP)

    [HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP) 题面 有三个人从一张N个点无重边的有向无环图上的三个点出发,每单位时间,他们分别选择当前 ...

  2. BestCoder Round #86 解题报告

    A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...

  3. HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002

    题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...

  4. BestCoder Round #86 部分题解

    Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/std ...

  5. HDU5808Price List Strike Back (BestCoder Round #86 E) cdq分治+背包

    严格按题解写,看能不能形成sum,只需要分割当前sum怎么由两边组成就好 #include <cstdio> #include <cstring> #include <c ...

  6. HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp

    #include <cstdio> #include <cstring> #include <cmath> #include <vector> #inc ...

  7. HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分

    分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...

  8. HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理

    分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...

  9. HDU5804 Price List (BestCoder Round #86 A)水题

    分析:大于总和输出1 #include <cstdio> #include <cstring> #include <algorithm> using namespa ...

随机推荐

  1. java环境配置

    一.下载安装sdk jdk和jre的区别: jdk:是编译环境(编译器),把java文件编译成class文件 jre:是运行环境(运行器),执行class文件需要使用jre eclipse开发出jav ...

  2. (转)理解MySQL——索引与优化

    参考资料:http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html ———————————— 全文: 写在前面:索引对查询的速度有着 ...

  3. JS 工厂模式

    1.什么是工厂模式 工厂模式是面向对象的设计模式,作用在于创建一个对象,mixin模式也是面向对象的设计模式,作用在于继承. 工厂模式定义一个接口,让实现这个接口的类来决定实例化哪个类,也就是说通过一 ...

  4. 去掉IE11的叉叉

    在 IE11 下,浏览器自作多情在 text input 组件上加一个 close 叉叉: 用CSS伪类定义: input::-ms-clear { display: none; }

  5. Druid初步学习

    Druid是一个JDBC组件,它包括三部分:  DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可管理的数据库连接池 ...

  6. R语言——七月

    这两个月没有写什么代码.也没做什么大项目,基本就是对以前写的那个用ggplot2可视化数据的项目做一些增增补补,大部分技术难关都在ggplot2和R语言EXCEL处理这里解决并总结了.然后业余帮人修改 ...

  7. [Machine Learning & Algorithm] 朴素贝叶斯算法(Naive Bayes)

    生活中很多场合需要用到分类,比如新闻分类.病人分类等等. 本文介绍朴素贝叶斯分类器(Naive Bayes classifier),它是一种简单有效的常用分类算法. 一.病人分类的例子 让我从一个例子 ...

  8. 解决table不能换行的问题与CSS之自动换行总结

    table不能换行问题 一般是:一行里面全是数字或是字母或者结尾有多个感叹号而导致 table不能换行,中文默认的会自动换行的,字母不能换行问题:style="table-layout:fi ...

  9. Solr5.4.0部署到Tomcat

    所用工具 下载 solr 5.4.0 版本:http://www.apache.org/dyn/closer.lua/lucene/solr/5.4.0 下载 Tomcat(6以上版本),另外可以根据 ...

  10. How do I enable log4net internal debugging?

    http://logging.apache.org/log4net/release/faq.html