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啦~(≧▽≦)/~啦啦啦 柱神来到了 ...
随机推荐
- android自定义控件(三) 增加内容 自定义属性 format详解
转自 http://www.gisall.com/html/35/160435-5369.html 1. reference:参考某一资源ID. (1)属性定义: <declare-stylea ...
- java-02 for循环,while循环
###############获取一个数字的每位数字############### #############1-100奇数和偶数和############## public class Sum { ...
- Seal Report结合MySQL数据库 报表展现_20161011
昨天留了草稿 未来得及发 今日补发一篇 seal report 操作类似excel数据透视表也包含行标签和列标签及值标签,行列代表的是数据指标的维度,值标签代表的是度量. seal report连接M ...
- 结合Mysql和kettle邮件发送日常报表_20161001
十一假期 参加婚礼 稍晚点发博 整体流程步骤是: 写SQL-导出到excel设定excel模板调整格式-设置kettle转换--设置kettle邮件作业--完成 第一.写SQL 保持最近12个周的数据 ...
- 洛谷P1220关路灯——区间DP
题目:https://www.luogu.org/problemnew/show/P1220 区间DP. 代码如下: #include<iostream> #include<cstd ...
- Python之常用模块(一)
time & datatime 模块 random os sys shutil json & picle time & datetime 时间戳(1970年1月1日之后 ...
- Component概念
转自:http://www.cnblogs.com/NEOCSL/archive/2012/05/06/2485227.html 1.总结 Component就是组建的意思,可以在DefaultPro ...
- <正则吃饺子> :关于微信支付的简单总结说明(二)
关于微信退款 一.官方文档 申请退款:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 二.退款流程 ...
- mongodb启动脚本
#!/bin/sh # #chkconfig: #description: mongodb start() { /usr/local/yunshipei/enterplorer/mongodb/bin ...
- Connection reset by peer的常见原因及解决办法
转自:https://blog.csdn.net/xc_zhou/article/details/80950753 1,如果一端的Socket被关闭(或主动关闭,或因为异常退出而 引起的关闭),另一端 ...