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. android自定义控件(六) 刷新

    三种得到LinearInflater的方法 a. LayoutInflater inflater = getLayoutInflater(); b. LayoutInflater localinfla ...

  2. javaScript运算符之in运算符

  3. css 3d box 实现的一些注意事项

    Test1.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. 发挥到极致的Asterisk SS7 解决方案【转】

    基于SS7的开源解决方案在国内已经安装了很多.很多用户都使用chan_ss7 开源协议栈作为呼叫中心,400电话,计费结算的系统.随着国内对开源Asterisk的认可程度越来越高. Asterisk让 ...

  5. CodeForces - 613D:Kingdom and its Cities(虚树+DP)

    Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in or ...

  6. HihoCoder1650 : 扁平化管理([Offer收割]编程练习赛38)(二分)

    描述 小Hi的公司包括CEO在内一共有N名员工.这N名员工的上下级关系形成树形结构,CEO处于树根,普通员工处于叶子节点. 现在公司希望管理扁平化,要求树形结构中的层级不超过L层.此外,假设A是B的直 ...

  7. 创建maven多模块项目

    一:创建父项目

  8. 算法导论笔记——第十八章 B树

    18.1 B树的定义  18.2 B树的基本操作 与一棵二叉搜索树一样,可以在从树根到叶子这个单程向下过程中将一个新的关键字插入B树中.为了做到这一点,当沿着树向下查找新的关键字所属位置时,就分裂沿途 ...

  9. spring-data-cassanra的简单使用

    之前写了JAVA操作cassandra驱动包,现在来看看spring-data对cassandra的支持.这里是spring-data-cassandra的官方文档:http://docs.sprin ...

  10. idea 调试技巧1

    1 多线程调试 开发过多线程应用的朋友应该有体会,有些时候,为了观察多个线程间变量的不同状态,以及锁的获取等,就会想到在代码里加个断点debug一下. 在IDE里断点停下来的时候,可以切换到另外的线程 ...