[ CodeForces 1064 B ] Equations of Mathematical Magic
\(\\\)
\(Description\)
\(T\) 组询问,每次给出一个 \(a\),求方程
\]
的方案数。
- \(T\le 10^3,a\le 2^{30}\)
\(\\\)
\(Solution\)
我菜又被巨佬 \(Diss\) 了......
考场 \(NC\) 问了爷们半懂不懂的就过了......
移项,得
\]
然后注意到满足这个性质的 \(x\) ,在二进制表示下一定是 \(a\) 的子集。
因为\(a\oplus x\)表示的是两者不交的部分的并集,再加上\(x\)表示的就是两个集合的并再加上 \(x\) 这一集合中 \(a\) 集合不包含的部分。
要是想要这个东西等于 \(a\) ,当且仅当 \(x\) 集合中不在 \(a\) 集合中的部分为空集。
然后就是统计 \(a\) 子集的个数。
显然一开始答案为 \(1\) ,遇到二进制位的一个 \(1\) 就答案个数就会翻倍。
\(\\\)
\(Code\)
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define R register
#define gc getchar
using namespace std;
typedef long long ll;
inline ll rd(){
ll x=0; bool f=0; char c=gc();
while(!isdigit(c)){if(c=='-')f=1;c=gc();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=gc();}
return f?-x:x;
}
ll x,ans=1;
void work(){
ans=1ll;
x=rd();
while(x){
if((x&1ll)==1ll) ans<<=1;
x>>=1;
}
printf("%I64d\n",ans);
}
int main(){
ll t=rd();
while(t--) work();
return 0;
}
[ CodeForces 1064 B ] Equations of Mathematical Magic的更多相关文章
- CF 1064B Equations of Mathematical Magic(思维规律)
Description Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for. ...
- B. Equations of Mathematical Magic
思路 打表找规律,发现结果是,2的(a二进制位为1总数)次方 代码 #include<bits/stdc++.h> using namespace std; #define ll long ...
- CF1064B 【Equations of Mathematical Magic】
题目要求解$a-(a\oplus x)-x=0$的解$x$的个数 移项得$a-x=a\oplus x$ $a$的二进制形式,应该是一个$01$串,异或的过程是不能影响到两个不同的位的,所以我们按位考虑 ...
- cf#516B. Equations of Mathematical Magic(二进制,位运算)
https://blog.csdn.net/zfq17796515982/article/details/83051495 题意:解方程:a-(a^x)-x=0 给出a的值,要求计算解(非负)的个数 ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- codeforces 495B. Modular Equations 解题报告
题目链接:http://codeforces.com/problemset/problem/495/B 题目意思:给出两个非负整数a,b,求出符合这个等式 的所有x,并输出 x 的数量,如果 ...
随机推荐
- java设计模式 -------- 行为模式 之 策略模式(4)
[本文是自己学习所做笔记.欢迎转载,但请注明出处:http://blog.csdn.net/jesson20121020] 上面3节实现了从最初的对整形数组排序到最后能够对全部类型都能够依据须要定义自 ...
- javascript遍历数组的两种方法
var array=new Array(); array [0]="北京"; array [1]="天津"; ...//solution 1 for(var i ...
- easyUI datagrid 时间格式化
从后台传过来的数据,其中含有日期字段,那么在前端的easyUI这里显示的话,会显得比较怪异,一大串,中间是个T,后面一大堆零,不知道是什么意思. 看来要进行格式化. 问题是,在哪里格式化? 如果在后端 ...
- 【bzoj3609】[Heoi2014]人人尽说江南好
可以算出合并多少次. #include<algorithm> #include<iostream> #include<cstdlib> #include<cs ...
- ramfs、rootfs和initramfs【转】
ramfs, rootfs and initramfs October 17, 2005 Rob Landley <rob@landley.net> =================== ...
- 【LIS】Luogu P1020 导弹拦截
昨天晚上看蓝书,看到了LIS问题的优化解法. 是比O(n方)更快的解法,实际上是一个常数优化. 先讲一下朴素的解法: 一个集合a,a[i]是第i个元素.设dp[i]为以编号为i的元素结尾的最长不上升子 ...
- 【OI】Kruskal & ufs (克鲁斯卡与并查集)
Kruskal是有关于最小生成树的算法. 这个算法非常好理解,用一句话来概括就是: 从小到大找不同集合的边. 那么,具体是怎样的呢. 1.先把所有顶点初始化为一个连通分量. 2.从所有边中选择最小的( ...
- HDU5806 NanoApe Loves Sequence Ⅱ
NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Ja ...
- YTU 2508: 武功秘籍
2508: 武功秘籍 时间限制: 1 Sec 内存限制: 128 MB 提交: 1384 解决: 438 题目描述 小明到X山洞探险,捡到一本有破损的武功秘籍(2000多页!当然是伪造的). 他 ...
- bzoj2157 旅游——LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2157 仍然是LCT模板题~ 不过有一些需要注意的地方,点和边的区分,0号点的 mx 和 mn ...