题目链接:https://atcoder.jp/contests/abc126/tasks/abc126_f

题目大意

  给定两个整数 M 和 K ,用小于 2M 的的所有自然数,每个两个,用这些数排成一个长度为 2M+1 的序列,使得序列满足以下条件:

  1. 每个自然数只能用 2 次。
  2. 设序列为 a,$\forall_{i < j}\ 满足a[i] == a[j]$有 a[i] xor a[i + 1] xor……xor a[j] == K。

  问这个序列是否存在,存在则输出任意一个,不存在输出 -1。

分析

  找规律。
  貌似很难,其实巨简单。
  首先,如果 K >=  2M ,那就不用考虑了,绝对异或不出来。
  其次,当 M == 1 时,K 为 0 则可行,K 为 1 则不可行。
  最后是 M > 1 的情况,这里举个 M = 3,K = 4 的例子,某一绝对正确的摆法如下:0,1,2,3,5,6,7,4,7,6,5,3,2,1,0,4,加粗的是 K,说服一下自己,在 M > 1 的时候都能这么摆(实际上确实能这么摆)。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< string, int > PSI;
typedef set< int > SI;
typedef vector< int > VI;
typedef map< int, int > MII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 3e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; LL N, M, K; int main(){
INIT();
cin >> M >> K;
N = ( << M) - ; if(K > N) cout << - << endl;
else if(M == ) {
if(K == ) cout << - << endl;
else cout << "0 0 1 1" << endl;
}
else {
For(i, , N) if(i != K) cout << i << " ";
cout << K << " ";
rFor(i, N, ) if(i != K) cout << i << " ";
cout << K << " ";
cout << endl;
}
return ;
}

最新文章

  1. nginx参数说明
  2. 防止浏览器拦截的window.open新窗口方案
  3. 再论 ASP.NET 中获取客户端IP地址
  4. 前端之JavaScript第一天学习(3)-JavaScript输出
  5. UVa 1312 Cricket Field (枚举+离散化)
  6. PowerShell管理Exchange
  7. java的集合框架之一
  8. js跳转页面方法
  9. C#代码实现隐藏任务栏、开始菜单和禁用任务管理
  10. cf C. New Year Ratings Change
  11. VBoxManage.exe: error: Resize hard disk operation for this format is not implemented yet!
  12. LA 3662 Another Minimum Spanning Tree (曼哈顿距离最小生成树 模板)
  13. android-misc-widgets四向(上下左右)抽屉bug修复版--转载
  14. eclipse导入包之后中文乱码
  15. PAT甲级 1004 树
  16. dojo中的xhrPost请求(JSON)
  17. linux 系统 cp: omitting directory 问题解决
  18. 从RGB扫描图到数字化等高线矢量图
  19. 071——VUE中vuex之使用getters计算每一件购物车中商品的总价
  20. 《Effective Java》读书笔记八(异常)

热门文章

  1. JCF——Map
  2. error C2872: “ACCESS_MASK”: 不明确的符号
  3. SQL server 数据库安装
  4. 【Java架构:基础技术】一篇文章搞掂:Spring Tool Suite(STS)
  5. (转)即时通讯IM OpenFire源码学习之三:在Eclipse中构建源码
  6. 批处理禁止指定的IE的加载项
  7. PAT_A1084#Broken Keyboard
  8. vue-router 路由配置
  9. Python 操作excel常见异常
  10. 第四记 Java异常