IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> 2021牛客多校训练7 I xay loves or -> 正文阅读

[C++知识库]2021牛客多校训练7 I xay loves or

题目

链接:https://ac.nowcoder.com/acm/contest/11258/I
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

xay loves or. He gives you x and s, you need to calculate how many positive integer y satisfy xor?y=sx \operatorname{or} y=sxory=s .

输入描述:

The first line contains two positive integers x and s .

It's guaranteed that 1≤x,s<2311\le x,s<2^{31}1≤x,s<231 .

输出描述:

Print the number of y satisfy xor?y=sx \operatorname{or} y=sxory=s .

示例1

输入

[复制](javascript:void(0)😉

2 5

输出

[复制](javascript:void(0)😉

0

解释与代码

给出x和s?,问存在多少个y使得x|y=s

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <limits.h>
#include <assert.h>
#include <functional>
#include <numeric>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb          push_back
#define ppb         pop_back
#define lbnd        lower_bound
#define ubnd        upper_bound
#define endl        '\n'
#define mll         map<ll,ll>
#define msl         map<string,ll>
#define mls         map<ll, string>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define vll         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define DEBUG       cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x)  trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ini(a)      memset(a,0,sizeof(a))
#define ini2(a,b)   memset(a,b,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define case        ll T;cin>>T;for(ll Q=1;Q<=T;Q++)
#define lowbit(x)   x&(-x)
#define pr          printf
#define sc          scanf
#define _           0
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DBG(x) \
    (void)(cout << "L" << __LINE__ \
    << ": " << #x << " = " << (x) << '\n')
#define TIE \
    cin.tie(0);cout.tie(0);\
    ios::sync_with_stdio(false);
//#define long long int

//using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF   = 0x3f3f3f3f;
const ll  LLINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e7*2+10;
const ll N = 5;

typedef struct LNode{
    int coef,index;
    struct LNode *next;
}LNode,*LinkList;

struct SegmentTree{
	int l, r;
	int dat;
}t[N*4];

bool cmp(int a,int b){
	return a>b;
}


void solve(){
	ll x, s, ans = 1, xx, ss;
	cin>>x>>s;
	xx = x,ss = s;
	ll a, b, cnt = 0;
	if (x>s) {
		cout<<0<<endl;
		return ;
	} else if (x<s) {
		for (; x; x>>=1,s>>=1) {
			if ((x&1) && (s&1)==0) {
				cout<<0<<endl;
				return ;
			} else if ((x&1) && (s&1)) {
				ans*=2;
			} else if ((x&1)==0 && (s&1)) {
				cnt = 1;
			}
		}
//		if (cnt) {
//			cout<<ans<<endl;
//		} else {
//			cout<<ans-1<<endl;
//		}
	} else {
		for (; x; x>>=1) {
			if (x&1) {
				ans*=2;
			}
		}
//		cout<<ans-1<<endl;//去除0 
	}
	if ((0|xx)==ss) {
		ans--;
	}
	cout<<ans<<endl;
}

int main()
{
//	TIE;
//    #ifndef ONLINE_JUDGE
//    freopen ("input.txt","r",stdin);
//    #else
//    #endif
	solve();
//    case{solve();}
//    case{cout<<"Case "<<Q<<":"<<endl;solve();}
//	return ~~(0^_^0);
}



  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-08-15 15:19:21  更:2021-08-15 15:22:16 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/20 5:27:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码