D. Ehab the Xorcist】的更多相关文章

题意: 略: 感觉被演了一波,这是CFdiv2吗? 算是这个构造题吧. 1 首先我们可以将u进行二进制拆分来考虑.加入u>v那么小与v的那些数在怎么拼接也无法使异或值为u. 比如二进制U=1 0 1 1 0.怎么才能异或成这个数呢?无非就是让1所在的位置的1的个数为奇数就行了,也就是构成异或成U的最小值为1000+100+10.如果大于v的话是不可能构成U的. 2 v>u&&(v-u)&1.这样的话最后一位置会多出来一个1,会改变异或值的奇偶性,与u相反,所以也是不可能…
\(如果觉得下面难以理解,可以去这里看一种较为简单的解法\):saf \(这个题嘛,首先要明确异或的性质:相同为0,不同为1.\) \(举个例子,我们来构造u=15和v=127的情况\) \(注意到,异或是二进制,我们把15的二进制写下来\) $$1111$$ \(\color{Red}{说明什么?说明至少二进制的1,2,3,4位数字出现了奇数次,二进制的其他位出现了偶数次.}\) \(你问我为什么?请看异或的定义,假如出现偶数次1相异或,仍然为0.\) \(那么我们可以构造出最终数列中,二进制…
\(\color{red}{Link}\) \(\color{blue}{\text{Solution:}}\) 题目要求构造一个最短的序列,使得异或和为\(u\),数列和为\(v\). 那么,因为是异或,所以最终序列的\(u\)对应的二进制位一定出现了奇数次,其他一定是偶数次. 显然\(u,v\)奇偶性不同或是\(u>v\)则无解.异或和显然小于数列和. 当\(u=v\)时,输出一个数\(u\)即可. 但\(u\not= v\)时,考虑下面情况: 令\(\delta=v-u,h=\frac{\…
题意: 寻找异或后值为 u,相加后和为 v 的最短数组. 思路: 异或得 u ,则 v 至少应大于等于 u ,且多出来的部分可以等分为两份相消. 即初始数组为 u , (v-u)/2 , (v-u)/2,之后即为特判或判断是否可以合并. #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll u,v;cin>>u>>v; ll a=(v-u)/2; if(v&…
1325A - EhAb AnD gCd 题意:随意找两个数是他们的最大公约数 GCD 与最小公倍数 LCM 之和为所给定的值. 思路:找一下规律 ,假设所给的 数位n, 那么我们将n分成 1 ,n-1,这两个数,总是附和我们的答案 收获:认真观察所给的条件,自己先构造一下,找找规律 1325B - CopyCopyCopyCopyCopy 题意 :给一个有n个元素的数组,将数组中的元素复制 n 次,将n复制结果拼接起来,形成以新的数组,让求严格递增子序列有多少个 思路:对给的数组排序去重复,剩…
人闲桂花落,夜静春山空. 月出惊山鸟,时鸣春涧中.--王维 A. EhAb AnD gCd You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x. As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b)…
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Ol…
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair…
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in su…
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 i 这棵子树包含 i 这个点的连通块的最大值, 就能求出答案, 然后知道最大值之后再就能求出几个连接件. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make…