[ 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 的数量,如果 ...
随机推荐
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...
- Hive之Order,Sort,Cluster and Distribute By
测试数据 create table sort_test( id int, name string ) row format delimited fields terminated by '\t' li ...
- SqlServer函数获取指定日期后的第某个工作日
获取工作日 需要编写一个SqlServer函数,F_getWorkday,传入两个参数,第一个为时间date,第二个参数为第几个工作日num.调用F_getWorkday后返回date之后的第num个 ...
- Android GIS开发系列-- 入门季(9) 定位当前的位置
利用MapView定位当前的位置 这里要用到Arcgis中的LocationDisplayManager这个类,由于比较简单.直接上代码: LocationDisplayManager locatio ...
- Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可。
Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可.
- Spring Boot中微信全局token的缓存实现
为什么要缓存token? 这里的token指的是微信JSAPI中基础支持的ACCESS_TOKEN,并非网页授权ACCESS_TOKEN.网页授权Token每天的调用次数没有限制,不需要缓存. 接口 ...
- poj 2728 最优比例生成树(01分数规划)模板
/* 迭代法 :204Ms */ #include<stdio.h> #include<string.h> #include<math.h> #define N 1 ...
- EC2的维护更新-总结篇及有效经验分享
2014年10月11日 号,我们对不到10%的EC2实例的完毕了重新启动.来预防不论什么与Xen安全通报(XSA-108)相关的安全风险. 日之前都有义务遵守相关问题的保密要求.直到它被向公众公布. ...
- 从零開始学android<Bitmap图形组件.四十七.>
android.graphics.Bitmap(位图)是Android手机中专门提供的用于操作图片资源的操作类,使用此类能够直接从资源文件之中进行图片资源的读取.而且对这些图片进行一些简单的改动. 经 ...
- JavaScript你所不知道的困惑(1)
困惑一: 先看一个样例: function test(){ message = "hi"; } test(); alert(message); 会输出字符串"hi&quo ...