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≤iN, 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 (122N−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 (122N−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 (122N−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.


Submit

思路:

要使得最上面的数是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 构造题的更多相关文章

  1. $AT2163\ Median\ Pyramid\ Easy$ 构造

    正解:构造 解题报告: 传送门$QwQ$ 考虑如果有两个相邻格子是相同数字那么它们以上这两列就都会是这列数字(显然$QwQ$? 所以考虑只要构造出第$n-1$行的中心和中心右侧($or$左侧一样的$Q ...

  2. AT2163 [AGC006B] Median Pyramid Easy

    需要一点灵感的题目. 可以发现这样一个事情,当三个数中有两个数相同时,中为数一定是这两个相同的数. 基于这个观察,我们想让每一行都存在这样两个相同的两个数,就一定能保证第一层的值为 \(x\) 了. ...

  3. cf251.2.C (构造题的技巧)

    C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...

  4. hdu4671 Backup Plan ——构造题

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...

  5. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  6. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

  7. BZOJ 3097: Hash Killer I【构造题,思维题】

    3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 36 ...

  8. CF1110E Magic Stones(构造题)

    这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c ...

  9. CDOJ 1288 旅游的Final柱 构造题

    旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了 ...

随机推荐

  1. fiddler篡改请求数据

    有时需要修改请求或返回结果来验证网站存在的漏洞,因此需要使用到fiddler的断点功能. 如何修改请求前数据? 1.设置请求前断点 Rules--Automatic breakpoints--befo ...

  2. erlang的map基本使用

    maps 适用于需要在运行时改变数据结构(record则不行)的场景,可以动态增加key 数据量不宜过大,具体多大没有实际数据, maps from_list  如果list表很长,则相应的耗时时间会 ...

  3. properties文件的解析

    此文章是从网上看到一篇实用小文章,感觉不过,摘录下来的!如有问题,可及时联系,可立刻做相应处理! Java读取.properties 配置文件的几种方法 在做java工程时, 经常会将一些配置信息放到 ...

  4. linux 进程学习笔记-暂停进程

    <!--[if !supportLists]-->Ÿ <!--[endif]-->暂停进程 int pause() 其会挂起当前进程直到有信号来唤醒或者进程被结束. 随便提一下 ...

  5. PS 滤镜— —水波效果

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  6. HihoCoder1654: XY游戏([Offer收割]编程练习赛39)(好久没写搜索)(已经超级简短了)

    描述 如下图所示,在4x4的棋盘上有X和Y两种棋子各若干枚:O表示空格. OXXY YOOX XOOY XOXX 小Hi每次可以选择任意一枚棋子,将它移动到上下左右相邻的空格中. 小Hi想知道最少移动 ...

  7. 把myeclipse中的web项目导入eclipse中不能编程web项目的解决办法

    title: 把myeclipse中的web项目导入eclipse中不能编程web项目的解决办法 tags: grammar_cjkRuby: true --- 右键单击项目,properties-- ...

  8. xgene:WGS,突变与癌,RNA-seq,WES

     人类全基因组测序06 SNP(single nucleotide polymorphism):有了10倍以上的覆盖深度以后,来确认SNP信息,就相当可靠了. 一个普通黄种人的基因组,与hg19这个参 ...

  9. DeleteDC ReleaseDC DeleteObject之间的区别

    DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...

  10. Linear Algebra - Determinant(几何意义)

    二阶行列式的几何意义 二阶行列式 \(D = \begin{vmatrix}a_1&a_2\\b_1&b_2\end{vmatrix} = a_1b_2 - a_2b_1\) 的几何意 ...