BestCoder Round #86
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");
}
;
}
这道题可以用线段树做,查询最大值,每次删掉一个点,等于单点更新一到两个点。之后复原一下即可。
#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);
}
;
}
多少个区间里的第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的更多相关文章
- [HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP)
[HDU5807] [BestCoder Round #86 1004] Keep In Touch (DP) 题面 有三个人从一张N个点无重边的有向无环图上的三个点出发,每单位时间,他们分别选择当前 ...
- BestCoder Round #86 解题报告
A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...
- HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002
题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...
- BestCoder Round #86 部分题解
Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/std ...
- HDU5808Price List Strike Back (BestCoder Round #86 E) cdq分治+背包
严格按题解写,看能不能形成sum,只需要分割当前sum怎么由两边组成就好 #include <cstdio> #include <cstring> #include <c ...
- HDU5807 Keep In Touch (BestCoder Round #86 D ) 分布式dp
#include <cstdio> #include <cstring> #include <cmath> #include <vector> #inc ...
- HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分
分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...
- HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理
分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...
- HDU5804 Price List (BestCoder Round #86 A)水题
分析:大于总和输出1 #include <cstdio> #include <cstring> #include <algorithm> using namespa ...
随机推荐
- TypeScript Generics(泛型)
软件工程的一个主要部分就是构建组件,构建的组件不仅需要具有明确的定义和统一的接口,同时也需要组件可复用.支持现有的数据类型和将来添加的数据类型的组件为大型软件系统的开发过程提供很好的灵活性. 在C#和 ...
- Linux(Centos6.5)用户名密码
用户列表文件:/etc/passwd用户组列表文件:/etc/group 查看系统中有哪些用户:cut -d : -f 1 /etc/passwd查看可以登录系统的用户:cat /etc/passwd ...
- 面试题目——《CC150》高等难题
面试题18.1:编写一个函数,将两个数字相加.不得使用+或其他算数运算符. package cc150.high; public class Add { public static void main ...
- 初识Docker和Windows Server容器
概览 伴随着Windows Server 2016 Technical Preview 3 (TP3)版本的发布,微软首次提供了Windows平台下地原生容器.它集成了Docker对Windows S ...
- [译]学习HTTP协议的请求行
原文:http://fiddler2.com/blog/blog/2013/02/13/understanding-the-request-line 最近有一位Fiddler用户问我一个问题: 我在使 ...
- UVALive 3644 X-Plosives
X-Plosives Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submit] ...
- kxbdSuperMarquee.js滚动的神器-推荐
http://code.ciaoca.com/jquery/kxbdmarquee/ 版本:jQuery v1.3.2+ 查看 Demo 下载 jQuery kxbdMarquee 文档目录 使用方法 ...
- css动画 animation
今天用css做了一个简单的三角上下移动的一个小动画,说白了就是在改变该物体的height值.除了这个方法,还可以用js. 一.在用css写动画时,一定要记住兼容性问题.如何解决该兼容性?在前面加内核前 ...
- Google疯了,竟然这样!
导读 一个小问题:你每天做什么事?当然了,好多事情,但是我可以指出一件事,你几乎每天都会用 Google 搜索,我说的对吗?现在,如果你是一位 Linux 用户,这里有另外一个问题:如果你甚至不用离开 ...
- POJ 3678 Katu Puzzle
Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 ...