862C - Mahmoud and Ehab and the xor(构造)
原题链接:http://codeforces.com/contest/862/problem/C
题意:给出n,x,求n个不同的数,使这些数的异或和为x
思路:(官方题解)只有n==2&&x==0时输出NO,接下来考虑YES的情况
先定义一个数pw=217(输出答案时保证不会出现重复数字)
因为 数x 完全可以由三个数异或得到,那么对于n>3的情况,先求1到n-3的异或和,得到y,如果y==x,那么剩下三个数为pw, pw*2, pw^(pw*2)(当x==0时,0, pw,pw^x的输出是不符合题意的),否则输出0, pw,pw^x^y。
n<=3的情况可以直接输出。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1e5+;
const int pw=<<;
int main()
{
int n,x;
scanf("%d %d", &n, &x);
if(n==&&x==)printf("NO\n");
else
{
printf("YES\n");
if(n==) printf("%d\n", x);
else if(n==) printf("%d %d\n", , x);
else if(n==) printf("%d %d %d\n", pw^x, pw<<, pw^(pw<<));
else
{
int res=;
printf("%d", );
for(int i=;i<=n-;i++){
res^=i;
printf(" %d", i);
}
if(res==x){
printf(" %d %d %d\n", pw, pw<<, pw^(pw<<));
}
else {
//cout<<'*'<<endl;
printf(" %d %d %d\n", , pw, pw^x^res);
}
}
}
return ;
}
862C - Mahmoud and Ehab and the xor(构造)的更多相关文章
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)
题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...
- Coderfroces 862 C. Mahmoud and Ehab and the xor
C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...
- 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...
- codeforces 862 C. Mahmoud and Ehab and the xor(构造)
题目链接:http://codeforces.com/contest/862/problem/C 题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了 由于数据x只有1e5,但是要求是 ...
- 【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor
[链接]h在这里写链接 [题意] 让你组成一个n个数的集合,使得这n个数的异或和为x; x<=1e5 每个数最大1e6; [题解] 1e5<=2^17<=2^18<=1e6的 ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
随机推荐
- springmvc+ehcache简单例子
这里采用的是spring3.2.ehcache2.7.tomcat7.0(必须) 1.web.xml <?xml version="1.0" encoding="U ...
- python 操作openpyxl导出Excel 设置单元格格式以及合并处理
贴上一个例子,里面设计很多用法,根据将相同日期的某些行合并处理. from openpyxl import Workbook from openpyxl.styles import Font, Fil ...
- How to use Nlog for ASP.NET Core with csproj
1. Add dependency in csproj manually or using NuGet Install the latest: NLog.Web.AspNetCore 4.5+ Upd ...
- vue-router路由详细
由于Vue在开发时对路由支持的不足,于是官方补充了vue-router插件.vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来.传统的页面应用,是用一些超链接来实现 ...
- 001/Go语言构建区块链(mooc)
1.区块链发展与现状 视频地址:https://www.imooc.com/video/17452 注意: 比特币与以太坊最大的区别在于: 以太坊引入了对图灵完美智能合约的支持,人们可以将任何业务逻辑 ...
- Java 位运算符和移位运算符
一,运算的位运算符: & ~ | ^ 主要是对二进制的位计算 : & : 两个操作数中位都为1 结果才为1 其他结果为0 forExample: 128 ...
- vue中的computed 与 watch
计算属性 computed 指通过计算得来的属性,用于监听属性的变化 computed里面的函数调用的时候 不需要加() 方法里必须有一个返回值 return computed中的函数不会通过事件去触 ...
- powerdisigner
- PHP的设计模式及场景应用介绍
有大量的文章解释什么是设计模式,如何实现设计模式,网络上不需要再写一篇这样的文章.相反,在本文中我们更多的讨论什么时候用和为什么要用,而不是用哪一个和如何使用. 我将会为这些设计模式描绘不同的场景和案 ...
- R语言基础篇——数据读写
1.键盘输入数据(适合小数据集) #创建一个指定模式但不含数据的变量 mydata<-data.frame(age=numeric(0),gender=character(0),weight=n ...