AT2165 Median Pyramid Hard 二分答案 脑洞题
无论再来多少次也不可能想到的写法。
二分一个最小的顶端值\(k\),大于设为\(1\)小于等于设为\(0\),可以证猜出来(你跟我说这可以?)如果存在两个连在一起的0/1那么它们会一直往上跑,还可以很容易就想到(容易?????)如果不存在相邻的情况(也就是交叉的那种)那么顶端答案一定是原先左右两边的值之一。。
不管了弃疗了。放代码。
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, a[N << 1];
int sma (int i, int j, int k) {
return a[i] <= k && a[j] <= k;
}
int big (int i, int j, int k) {
return a[i] > k && a[j] > k;
}
int check (int k) {
for (int i = 0; i < n - 1; ++i) {//枚举距离判断
if (big (n + i, n + i + 1, k) || big (n - i, n - i - 1, k)) return 0;
if (sma (n + i, n + i + 1, k) || sma (n - i, n - i - 1, k)) return 1;
}
return sma (1, 1, k);//没有重合的特判
}
int main(){
cin >> n;
for (int i = 1; i <= (n << 1) - 1; ++i) {
cin >> a[i];
}
int l = 1, r = 2 * n - 1, ans;
while (l < r) {//二分判断
int mid = (l + r) >> 1;
if (check (mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << r;
return 0;
}
AT2165 Median Pyramid Hard 二分答案 脑洞题的更多相关文章
- Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- AtCoder Regular Contest 101 (ARC101) D - Median of Medians 二分答案 树状数组
原文链接https://www.cnblogs.com/zhouzhendong/p/ARC101D.html 题目传送门 - ARC101D 题意 给定一个序列 A . 定义一个序列 A 的中位数为 ...
- AT2165 Median Pyramid Hard
题目链接:戳我 一看范围1e5,往二分上想. 可是再怎么也没有想到这个神仙的二分答案qwq 我们二分一个数x,设比他大的数为1,小于等于他的数为0.那么我们就可以把原来的那个转化成一个01塔. 然后我 ...
- [AGC006] D - Median Pyramid Hard 二分
Description 现在有一个NN层的方块金字塔,从最顶层到最底层分别标号为1...N1...N. 第ii层恰好有2i−12i−1个方块,且每一层的中心都是对齐的. 这是一个N=4N=4的 ...
- CF 1042 A Benches —— 二分答案(水题)
题目:http://codeforces.com/problemset/problem/1042/A 代码如下: #include<iostream> #include<cstdio ...
- BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案
二分答案水题. #include <cstdio> #include <cstring> #include <iostream> #include <algo ...
- 【BZOJ4552】排序(线段树,二分答案)
[BZOJ4552]排序(线段树,二分答案) 题面 BZOJ 题解 好神的题啊 直接排序我们做不到 怎么维护? 考虑一下,如果我们随便假设一个答案 怎么检验它是否成立? 把这个数设成\(1\),其他的 ...
- 【BZOJ3993】星际战争(网络流,二分答案)
[BZOJ3993]星际战争(网络流,二分答案) 题面 Description 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战.在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团 ...
- BZOJ_3969_[WF2013]Low Power_二分答案
BZOJ_3969_[WF2013]Low Power_二分答案 Description 有n个机器,每个机器有2个芯片,每个芯片可以放k个电池. 每个芯片能量是k个电池的能量的最小值. 两个芯片的能 ...
随机推荐
- Ubuntu Firefox HTML5
sudo apt-get install ubuntu-restricted-extras
- react 自我小计
1.react中的方法调用,在onClick事件中不需要加小括号. <button onClick={this.show}>方法的调用</button> show(){ con ...
- 【NLP】How to Generate Embeddings?
How to represent words. 0 . Native represtation: one-hot vectors Demision: |all words| (too large an ...
- IntelliJ IDEA default settings 全局默认设置
可以通过以下两个位置设置IDEA的全局默认设置: 以后诸如默认的maven配置就不需要每次都重复配置了?
- github-share报错无法读取远程仓库
报错:github Could not read from remote repository 1.github创建仓库成功,而push报告此错误 2.考虑远程仓库名与本地项目名/文件夹名不匹配 3. ...
- LOJ6433 [PKUSC2018] 最大前缀和 【状压DP】
题目分析: 容易想到若集合$S$为前缀时,$S$外的所有元素的排列的前缀是小于$0$的,DP可以做到,令排列前缀个数小于0的是g[S]. 令f[S]表示$S$是前缀,转移可以通过在前面插入元素完成. ...
- Codeforces986C AND Graph 【位运算】【dfs】
题目大意: 一张$ m $个编号互异点图,最大不超过$ 2^n $,若两个编号位与为0则连边,问连通块数量. 题目分析: 考虑怎样的两个点会连边.这种说法对于A和B两个点来说,就相当于B在A的0的子集 ...
- Java7后try语句的优化
原始的写法 先来看一段老代码 OutputStream out = null; try { out = response.getOutputStream() } catch (IOException ...
- MT【310】均值不等式
(2014北约自主招生)已知正实数$x_1,x_2,\cdots,x_n$满足$x_1x_2\cdots x_n=1,$求证:$(\sqrt{2}+x_1)(\sqrt{2}+x_2)\cdots(\ ...
- 【模板】cdq分治代替树状数组(单点修改,区间查询)
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #in ...