Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A
题意:
告诉你s 和 x,a + b = s a xor b = x a, b > 0。 让你求符合条件的a b有多少对
思路:
a + b = s , a ^ b = x ==> s - x = (a & b) * 2
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[], b[];
int main()
{
LL s, x;
cin >> s >> x;
LL y = s - x;
if(y % || x > s) {
cout << << endl;
} else {
y /= ;
int pos1 = , pos2 = , cnt = , fuck = y ? : ;
for( ; x; ++pos1, x >>= ) {
if(x & ) {
++cnt;
a[pos1] = ;
}
}
for( ; y; ++pos2, y >>= ) {
if(y & )
b[pos2] = ;
}
int ok = ;
for(int i = ; i < max(pos1, pos2); ++i) {
if(a[i] && b[i]) {
ok = ;
break;
}
}
if(ok) {
if(fuck) {
cout << (1LL << ((LL)cnt)) << endl;
} else {
cout << (1LL << ((LL)cnt)) - << endl;
}
} else {
cout << << endl;
}
}
return ;
}
Codeforces 627 A. XOR Equation (数学)的更多相关文章
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- Codeforces Little Dima and Equation 数学题解
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 627A XOR Equation(思路)
题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...
- Codeforces635C XOR Equation【数学】
题目链接: http://codeforces.com/contest/635/problem/C 题意: 给定两个数的和s及异或x,求两个数的可能情况. 分析: 我们有公式a+b=a& b∗ ...
- CodeForces 635C XOR Equation
位运算. 又涨姿势了:$a + b = (aXORb) + 2*(aANDb)$,$ (aXORb)$是不进位的部分,$2*(aANDb)$为进位之后的部分,相加就是$a + b$. 知道了这个转换, ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- Codeforces 617 E. XOR and Favorite Number
题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...
- Codeforces 617E:XOR and Favorite Number(莫队算法)
http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...
- codeforces 617 E. XOR and Favorite Number(莫队算法)
题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...
随机推荐
- hdu 1226 超级密码(bfs+余数判重)
题意:略过 分析:用m个数字组成一个能够被n整除的c进制数的最小值,实际上本题的关键就在于这个最小值上. 首先确定我们的思路是从小到大寻找.先查看一位数,即查看着m个数字是否能被n整除:若不能,就查 ...
- HDU2027 统计元音
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; //此处 ...
- NTP时间服务器配置与解析
NTP时间服务器配置与解析 Edit By ZhenXing_Yu 目 录 编译安装ntp server 2 修改ntp.conf配置文件 2 配置时间同步客户机 2 在服务端验证: 3 在客户端进行 ...
- 四 AndEngine 画线
package com.example.AndEngineExample02; import org.anddev.andengine.engine.Engine;import org.anddev. ...
- 几种Menu和几种对话框
一.Menu 1.OptionsMenu(弹出菜单) (1)显示弹出菜单布局必须要重写的方法 onCreateOptionsMenu 该方法必须返回true ...
- 使用C#代码发起K2 Blackpearl流程
转:http://www.cnblogs.com/dannyli/archive/2011/08/02/2125285.html 使用C#代码,发起一个K2的流程,其形式和链接SQL Server数据 ...
- iOS 开发者必不可少的 75 个工具,你都会了吗
如果你去到一位熟练的木匠的工作室,你总是能发现他/她有一堆工具来完成不同的任务. 软件开发同样如此.你可以从软件开发者如何使用工具中看出他水准如何.有经验的开发者精于使用工具.对你目前所使用的工具不断 ...
- android LinearLayout 实现两端对齐
<?xml version="1.0″ encoding="utf-8″?> <LinearLayout xmlns:android="http://s ...
- WPF为提示信息文本增加闪烁效果
程序通常需要显示某些提醒用户警示的信息,如:收件箱(40)其中数量闪烁就会起到警示效果.可以适用如下Storyboard实现: <ItemsControl.ItemTemplate> &l ...
- git/github初级运用自如(zz)
----//git/github环境配置 一 . github上创建立一个项目 用户登录后系统,在github首页,点击页面右下角“New Repository” 填写项目信息: project n ...