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的矩阵,每个位置有一个元素,给定一个起点 ...
随机推荐
- JDBC通过配置文件(properites)读取数据库配置信息
扫盲: Classloader 类加载器,用来加载 Java 类到 Java 虚拟机中.与普通程序不同的是.Java程序(class文件)并不是本地的可执行程序.当运行Java程序时,首先运行JVM( ...
- cpu 基础知识
认识cpu(中央处理器简称处理器)也叫CPU,Central Processing Unit线程是安排CPU执行的最小单位 四核八线程内涵: 每个单位时间内,一个CPU只能处理一个线程(操作系统:th ...
- http协议cookie结构分析
Http协议中Cookie详细介绍 Cookie总是保存在客户端中,按在客户端中的存储位置,可分为内存Cookie和硬盘Cookie.内存Cookie由浏览器维护,保存在内存中,浏览器关闭后就消失 ...
- JS判断指定dom元素是否在屏幕内的方法实例
前言 刷网页的时候,有时会遇到这样一个情景,当某个dom元素滚到可见区域时,或者图片的懒加载效果,它就会展现显示动画,十分有趣.那么这是如何实现的呢? 实现原理 想要实现这个功能,就要知道具体的实现原 ...
- DBlink的创建与删除
创建方式一: create [public] database link link名称 connect to 对方数据库用户identified by 对方数据库用户密码 using '对方数据库i ...
- 学习笔记——OS——引论
学习笔记--OS--引论 操作系统的定义 操作系统是一组管理计算机硬件资源的软件集合: 用户和计算机硬件之间的接口 控制和管理硬件资源 实现对计算机资源的抽象 计算机系统硬件 冯诺依曼体系结构和哈佛结 ...
- ubuntu 服务器配置
一.apache.svn服务器的搭建 1.安装apache2 apt-get install apache2 2.下载安装svn服务和svn-apache连接库 sudo apt-get instal ...
- EasyX_无法填充圆颜色的问题
官网:https://www.easyx.cn/ 在线帮助文档:https://docs.easyx.cn/ 目标:生成一个边框为黄色,填充为蓝色的圆 遇到的问题:使用以下代码,只能生成边框为黄色的圆 ...
- linux学习第十七天(NFS、AUTOFS文件共享配置,DNS配置)
一.NFS(网络文件系统,实现linux系统上文件共享) 服务器配置 yum install nfs-utils (安装NFS软件包) iptables -F (清空防火墙) service ip ...
- Activity Monitor 闪退 & 无法进入睡眠
情况描述 黑苹果主机突然无法进入睡眠. 考虑到可能是后台程序阻碍了系统正常进入睡眠, 于是想要通过Activity Monitor查看系统的活动情况,然而,Activity Monitor闪退. 重 ...