CF 1064B Equations of Mathematical Magic(思维规律)
Description
Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: a−(a⊕x)−x=0
for some given a, where ⊕ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some x
, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.
Input
Each test contains several possible values of a
and your task is to find the number of equation's solution for each of them. The first line contains an integer t (1≤t≤1000
) — the number of these values.
The following t
lines contain the values of parameter a, each value is an integer from 0 to 230−1
inclusive.
Output
For each value of a
print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of a
appear in the input.
One can show that the number of solutions is always finite.
Sample Input
3
0
2
1073741823
1
2
1073741824 题目意思:已知a,求解方程a−(a⊕x)−x=0,x的可能情况有几种。
解题思路:通过移项我们可以得到a⊕x=a-x,那么我们需要找一下这两个表达式的联系和区别。因为是异或,我们将这两个数放在二进制下比较。
1^1=0 1-1=0
1^0=1 1-0=1
0^0=0 0-0=0
0^1=1 0-1=1//借位
我们可以发现,当a=1时,不管对于位上的x是0还是1,都是成立的,但当a=0时,只有x=0成立。
因而发现a=1时可以有两种选择,那么只需要统计a的二进制中1的个数,根据乘法原则就能求出所有解的个数了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
/*
1^1=0 1-1=0
1^0=1 1-0=1
0^0=0 0-0=0
0^1=1 0-1=1//借位
*/
int main()
{
int a,b,t,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d",&a);
ans=;
while(a)
{
if(a%)
{
ans=ans*;
}
a/=;
}
printf("%d\n",ans);
}
return ;
}
CF 1064B Equations of Mathematical Magic(思维规律)的更多相关文章
- cf#516B. Equations of Mathematical Magic(二进制,位运算)
https://blog.csdn.net/zfq17796515982/article/details/83051495 题意:解方程:a-(a^x)-x=0 给出a的值,要求计算解(非负)的个数 ...
- 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$串,异或的过程是不能影响到两个不同的位的,所以我们按位考虑 ...
- [ CodeForces 1064 B ] Equations of Mathematical Magic
\(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...
- UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律
UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...
- 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 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- [ 9.29 ]CF每日一题系列—— 765B字符串规律
Description: 遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果 Solution: 哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了 Code: #include ...
- CF 1042 E. Vasya and Magic Matrix
E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...
随机推荐
- html中radio、checkbox选中状态研究
我们在web页面开发中经常需要让单选框.复选框进行选中或者不选中的操作, 我们可以在元素中添加checked属性 或者添加checked="checked" 都可以让某个选项默认选 ...
- P2758 编辑距离
题目描述 设A和B是两个字符串.我们要用最少的字符操作次数,将字符串A转换为字符串B.这里所说的字符操作共有三种: 1.删除一个字符: 2.插入一个字符: 3.将一个字符改为另一个字符: !皆为小写字 ...
- ZCMU 1019: 分金币
解题思路: 附上刘汝佳老师的解题过程: 首先最终每个人的金币数量可以计算出来,它等于金币总数除以人数n.接下来用M来表示每个人最终拥有的金币数. 现在假设编号为 i 的人初始有Ai 枚金币,对于1号来 ...
- ASP.NET Core 如何实现404错误跳转到主页
假如用户在Web浏览器上敲错了URL,访问了ASP.NET Core站点下一个不存在的URL地址,那么默认情况下ASP.NET Core会返回给浏览器著名的404错误,那么有什么办法可以让ASP.NE ...
- Map的复制
Map的复制不可以直接使用=赋值 Map<String,Object> map1 = new HashMap<String,Object>(); Map<String,O ...
- 网格布局(GridLayout) 行数与列数
1.如果网格布局对象未指定具体的“行数”和“列数”,那么它将拥有1行和动态的列数. import java.awt.Button; import java.awt.Frame; import java ...
- 历年至今TVB剧集目录(持续更新...我已看过的推荐)
2019年度TVB剧集 <> 主演: <> 主演: 2018年度TVB剧集 <大帅哥> 主演:张卫健,蔡思贝,洪永城,曹永廉 <守护神之保险调查> 主演 ...
- LaTeX表格绘制备忘之Go语言中的几个表
以下绘制的表格选自<Go语言 云动力>一书.这些表格比较简单,LaTeX语句也比较简单. 完整代码: % 博客园陆巍的博客 https://www.cnblogs.com/atth ...
- Java基础加强——动态代理
代理模式: 为其他对象提供一种代理以控制对这个对象的访问. 代理模式主要分为两类: 静态代理:由程序员创建或特定工具自动生成源代码,再对其编译.在程序运行前,代理类的.class文件就已经存在了. ...
- 20155238 2016-2017-2 《Java程序设计》第四周学习总结
教材学习内容总结 继承 extends public class SwordsMan extends Role 检查语法逻辑,从=右边向左边读.编译程序就是语法检查器. 重新定义行为 public v ...