B - Median Pyramid Easy 构造题
B - Median Pyramid Easy
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≤i≤N, step i consists of 2i−1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, …, 2N−1) into the blocks of step N. Then, he wrote integers into all remaining blocks, under the following rule:
- The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only remembers that the integer written into the block of step 1 was x.
Construct a permutation of (1, 2, …, 2N−1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.
Constraints
- 2≤N≤105
- 1≤x≤2N−1
Input
The input is given from Standard Input in the following format:
N x
Output
If no permutation of (1, 2, …, 2N−1) could have been written into the blocks of step N, print No
.
Otherwise, print Yes
in the first line, then print 2N−1 lines in addition.
The i-th of these 2N−1 lines should contain the i-th element of a possible permutation.
Sample Input 1
4 4
Sample Output 1
Yes
1
6
3
7
4
5
2
This case corresponds to the figure in the problem statement.
Sample Input 2
2 1
Sample Output 2
No
No matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.
思路:
要使得最上面的数是x。那么,特判完特殊情况后。(就是输出NO的,)
如果x==1或者x==2*n-1是不行的,因为他们不可能是中间数。不能弄上去。
否则我们尽可能使得倒数第二行得x个数尽量多。
这样是最优的。
比如x=4 n = 4
那么应该是1 6 3 4 5 2 7
有三个4弄上去了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> const int maxn = 2e5 + ;
int a[maxn];
bool book[maxn];
void work() {
int n, x;
scanf("%d%d", &n, &x);
if (x == || x == * n - ) {
printf("No\n");
return;
}
int t = * n - ;
a[t / + ] = x;
a[t / ] = x - ;
a[t / + ] = x + ;
book[x] = book[x - ] = book[x + ] = ;
if (t / - > && x + <= t) {
a[t / - ] = x + ;
book[x + ] = ;
}
if (t / + <= t && x - >= ) {
a[t / + ] = x - ;
book[x - ] = ;
}
int to = ;
for (int i = ; i <= t; ++i) {
if (a[i] != ) continue;
while (book[to] != ) to++;
a[i] = to;
book[to] = ;
}
printf("Yes\n");
for (int i = ; i <= t; ++i) {
printf("%d\n", a[i]);
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
B - Median Pyramid Easy 构造题的更多相关文章
- $AT2163\ Median\ Pyramid\ Easy$ 构造
正解:构造 解题报告: 传送门$QwQ$ 考虑如果有两个相邻格子是相同数字那么它们以上这两列就都会是这列数字(显然$QwQ$? 所以考虑只要构造出第$n-1$行的中心和中心右侧($or$左侧一样的$Q ...
- AT2163 [AGC006B] Median Pyramid Easy
需要一点灵感的题目. 可以发现这样一个事情,当三个数中有两个数相同时,中为数一定是这两个相同的数. 基于这个观察,我们想让每一行都存在这样两个相同的两个数,就一定能保证第一层的值为 \(x\) 了. ...
- cf251.2.C (构造题的技巧)
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- hdu4671 Backup Plan ——构造题
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
- CF1110E Magic Stones(构造题)
这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c ...
- CDOJ 1288 旅游的Final柱 构造题
旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了 ...
随机推荐
- 001-Bootstrap栅格系统
1 安装和基本使用 外文官网 中文官网 可以正常下载使用 有三个文件夹, 分别是css, fonts, js bootstrap/ ├── css/ │ ├── bootstrap.css │ ├── ...
- poj 2689Prime Distance(区间素数)埃氏筛法
这道题的L和R都很大,所以如果直接开一个1~R的数组明显会超时.但是R-L并不大,所以我们考虑把这个区间(L--R)移动到(1--(R-L+1))这个区间再开数组(就是把每个数减L再加1).接下来先用 ...
- [POI 2000] 公共串
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2946 [算法] 建立多串后缀树 对于后缀树上的每个点 , 判断该节点所代表的等价类是 ...
- 洛谷 U6931 灯光
题目背景 明天就是校园活动了,小明作为场地的负责人,将一切都布置好了.但是在活动的前几天,校园里的灯却都坏掉了,无奈之下,只好再去买一批灯.但是很遗憾的是,厂家看马上要过年了,就没有在进货了,现在只剩 ...
- Java 日志记录规则
Java 日志记录规则 规则一:日志是面向读者的 我们不应该让无价值的信息使日志文件变得乱糟糟,比如说完整打印所有的实体字段. 通常,实体名字和其逻辑关键字足以识别在表格中的一条记录了. 规则二:匹配 ...
- Scala Beginner
开始学习Scala,下面的内容大部分从Scala官网翻译过来,有几个地方翻译的不是很好,表述不清楚的地方大家可以浏览Scala官网,多指教. Scala offical website is http ...
- caffe Dtype
http://blog.luoyetx.com/2015/10/reading-caffe-2/
- Linux命令总结_查看主机磁盘使用
1.dh -h 查看各个挂载点的使用量 2.du -sh *(星号表示当前所有文件夹)可以查看当前目录下各个文件夹的大小,-s表示只显示当前文件夹(不加-s你可以看到所有文件夹下的子文件夹的大小,太多 ...
- Weblogic学习
1.WebLogic目录介绍: coherence:集群组件 modules:第三方的模块包 user_projects:存放域的文件夹(必须要创建域) utils 工具包 uninstall ...
- [hiho1584]Bounce
题意:找出图中经过一次的格子个数. 解题关键: 组合数学的思想:先找出总的经过格子的次数,然后减去2倍的经过2次的格子个数. 1.总的求法:将长延展,当延展到n倍时,能够恰好到达右边的两个端点,则总格 ...