Codeforces Round #628 (Div. 2) D. Ehab the Xorcist(规律+结论)

题目链接
在这里插入图片描述
思路:硬是根据样例来猜结论。。。
首先u+t+t=v,这个肯定是一组答案,因为t^t=0,那么就来考虑一下能不能把长度给缩小,把u+t和t给判断一下就行。至于什么情况下无解呢?就是u>v或者u和v奇偶性不同的时候。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+1;
int mx,id,n,cnt=1,a[maxn],b[maxn],r[maxn];
map<int,int>p[maxn]; 
vector<int>g[maxn];
int main()
{
  ll x,y;
  cin>>x>>y;
    if(x>y||(y-x)&1) {printf("-1\n");return 0;}
    if(x==y&&y==0){
    	printf("0\n");return 0;
	}
	if(x==y&&y!=0){
		cout<<1<<endl;
    	printf("%lld\n",x);return 0;
	}
	ll t1=(y-x)/2,t2=(y+x)/2;
	if((t1^t2)==x&&(t1+t2==y)){
		cout<<2<<endl;
		cout<<t1<<" "<<t2<<endl;
		return 0;
	}
	cout<<3<<endl;
	cout<<x<<" "<<t1<<" "<<t1<<endl;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值