题目链接: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 (数学)的更多相关文章

  1. 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 ...

  2. Codeforces Little Dima and Equation 数学题解

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. Codeforces 627A XOR Equation(思路)

    题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...

  4. Codeforces635C XOR Equation【数学】

    题目链接: http://codeforces.com/contest/635/problem/C 题意: 给定两个数的和s及异或x,求两个数的可能情况. 分析: 我们有公式a+b=a& b∗ ...

  5. CodeForces 635C XOR Equation

    位运算. 又涨姿势了:$a + b = (aXORb) + 2*(aANDb)$,$ (aXORb)$是不进位的部分,$2*(aANDb)$为进位之后的部分,相加就是$a + b$. 知道了这个转换, ...

  6. Codeforces 242E:XOR on Segment(位上的线段树)

    http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...

  7. Codeforces 617 E. XOR and Favorite Number

    题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...

  8. Codeforces 617E:XOR and Favorite Number(莫队算法)

    http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...

  9. codeforces 617 E. XOR and Favorite Number(莫队算法)

    题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...

随机推荐

  1. sed总结

    [-] 简介 调用方式 选项 命令集合 寻址方式 基本用法 文件操作 附加-插入-修改文本 删除文本 替换文本 转换文本 补充 ------------------------------------ ...

  2. 模拟实现STL中的list

    #pragma once #include<iostream>using namespace std;#include<assert.h> template<class ...

  3. *ecshop 限制文章帮助文章显示条数

    1.打开 /themes/default/library/help.lbi 文件 <!-- {foreach from=$help_cat.article item=item} --> & ...

  4. 【英语】Bingo口语笔记(45) - Pass系列

  5. UITabbar item 设置笔记

    很长一段时间都是用代码来写UITabbarController,试着用xib来写一次,但是遇到tabbar item的图标自定义的时候不知道从何入手,比如定义选定前和选定后的icon图片,这地方还是不 ...

  6. 不要随随便便的distinct和order by

    相关查询非常慢,通过程序拿到了相关sqlexplainexplain SELECT DISTINCT(o.orders_id), o.oa_order_id, customers_email_addr ...

  7. 【转】Eclipse快捷键 10个最有用的快捷键----不错

    原文网址:http://www.open-open.com/bbs/view/1320934157953 1.选中你要加注释的区域,用ctrl+shift+C 会加上//注释2.先把你要注释的东西选中 ...

  8. Asp.net 访问数据库的几种方式

    ASP.NET中连接数据库的各种方法 连接SQL数据库的方法:(一).在Web.Config中创建连接字符串:1.<add name="ConnectionString" c ...

  9. Java并发编程-volatile

    一. volatite 简述Java 语言提供了一种稍弱的同步机制,即 volatile 变量.用来确保将变量的更新操作通知到其他线程,保证了新值能立即同步到主内存,以及每次使用前立即从主内存刷新. ...

  10. Introduction 引言

    The risk of software failure has never been greater. The estimated annual economic impact ranges fro ...