codeforces 862 C. Mahmoud and Ehab and the xor(构造)
题目链接:http://codeforces.com/contest/862/problem/C
题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了
由于数据x只有1e5,但是要求是1e6,而且我们知道3个数可以组合成任意数也就是说n-3的数从1~1e5直接任意找然后使得其总xor为sum
当sum=x时(定义Max=1<<17 > 1e5)那么这三个数只要组成0就行,当sum!=x时那么这三个数只要构成sum^x就行,这3个数从1e5~1e6中找
很好找的。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; int main() {
int n , x;
cin >> n >> x;
if(n == ) {
cout << "YES" << endl;
cout << x << endl;
}
else if(n == ) {
if(x == ) {
cout << "NO" << endl;
}
else {
cout << "YES" << endl;
cout << << ' ' << x << endl;
}
}
else {
int Max = << ;
int sum = ;
cout << "YES" << endl;
for(int i = ; i <= n - ; i++) {
cout << i << ' ';
sum ^= i;
}
if(sum == x) {
cout << Max << ' ' << (Max << ) << ' ' << (Max ^ (Max << )) << endl;
}
else {
cout << << ' ' << (Max ^ sum) << ' ' << (Max ^ x) << endl;
}
}
return ;
}
codeforces 862 C. Mahmoud and Ehab and the xor(构造)的更多相关文章
- 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 - 862C Mahmoud and Ehab and the xor(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness
Mahmoud and Ehab and the bipartiteness Mahmoud and Ehab continue their adventures! As everybody in ...
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
http://codeforces.com/problemset/problem/862/B 题意: 给出一个有n个点的二分图和n-1条边,问现在最多可以添加多少条边使得这个图中不存在自环,重边,并且 ...
- Codeforces 959 D Mahmoud and Ehab and another array construction task
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...
- Codeforces 959 E Mahmoud and Ehab and the xor-MST
Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him ...
- 【构造】【分类讨论】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, ...
随机推荐
- 【Intellij】Hot Swap Failed & class reloaded
用 Intellij IDEA 编译程序时遇到了这个问题,如下图所示: 对结果貌似没什么影响,但暂时没找到出现这个情况的原因……
- VSTO之PowerPoint(PPT)插件开发常用API汇总
VSTO简介 VSTO(Visual Studio Tools for Office )是VBA的替代,使得开发Office应用程序更加简单,并且用VSTO来开发office应用程序可以使用Visua ...
- 在 dotnet core (C#)下的颜色渐变
直接使用等比例抽样算法,连同透明度一起计算. public IList<Color> ShadeColors(Color c1, Color c2, int resultCount) { ...
- C#开发可播放摄像头及任意格式视频的播放器
前言 本文主要讲述,在WPF中,借助Vlc.DotNet调用VLC类库,实现视频播功能,下面我们先来做开发前的准备工作. 准备工作 首先,我们创建一个项目WpfVLC,然后,进入Neget搜索Vlc. ...
- Asp.Net Core WebAPI+PostgreSQL部署在Docker中
PostgreSQL是一个功能强大的开源数据库系统.它支持了大多数的SQL:2008标准的数据类型,包括整型.数值值.布尔型.字节型.字符型.日期型.时间间隔型和时间型,它也支持存储二进制的大对像, ...
- Tomcat源码分析 (五)----- Tomcat 类加载器
在研究tomcat 类加载之前,我们复习一下或者说巩固一下java 默认的类加载器.楼主以前对类加载也是懵懵懂懂,借此机会,也好好复习一下. 楼主翻开了神书<深入理解Java虚拟机>第二版 ...
- EFCore + MySql codeFirst 迁移 Migration出现的问题
第二次使用Migration update-database的时候出现以下错误: System.NotImplementedException: The method or operation is ...
- ABP 配置全局数据过滤器 II
第一篇 那种写法有些复杂, 简单办法是直接注入 切换到 ***.EntityFramework 项目 在Uow 里面创建 ***EfUnitOfWork.cs 类 public class Coope ...
- 深度搜索(dfs)+典型例题(八皇后)
深度优先搜索简称深搜,从起点出发,走过的点要做标记,发现有没走过的点,就随意挑一个往前走,走不了就回退,此种路径搜索策略就称为“深度优先搜索”,简称“深搜”. 如上面的图所示:加入我们要找一个从V0到 ...
- idea2019.2安装指南
先去官网下载idea官网地址 下载UItimate版本点击 DOWNLOAD等待下载完成 点击ideaIU-2019.2.exe一路next 可以在这一步选一下 继续next ...