首页 > 其他分享 >Codeforces Round #847 (Div. 3) E. Vlad and a Pair of Numbers(位运算)

Codeforces Round #847 (Div. 3) E. Vlad and a Pair of Numbers(位运算)

时间:2023-01-30 23:35:30浏览次数:53  
标签:847 Vlad const cout int LL Codeforces cin

https://codeforces.com/contest/1790/problem/E

题目大意:

两个正数a和b (a,b>0)。a⊕b=(a+b)/2,  a⊕b==x。

找到任何合适的a和b,或者不存在"-1"。 
inputCopy
6
2
5
10
6
18
36
outputCopy
3 1
-1
13 7
-1
25 11
50 22

异或(xor)⊕ ^
a+b == a^b + 2(a&b) == 2 * x
(a^b)
2 == a^b + 2(a&b)
a^b == 2
(a&b)

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4002;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL x;
        cin>>x;
        LL a=x/2,b=x+x/2;
        if((a^b)==x&&x*2==(a+b)) cout<<a<<" "<<b<<endl;
        else cout<<"-1"<<endl;
    }
    return 0;
}

标签:847,Vlad,const,cout,int,LL,Codeforces,cin
From: https://www.cnblogs.com/Vivian-0918/p/17077517.html

相关文章

  • Codeforces Round #846 (Div. 2) 解题报告
    前情提要:我是沙币比赛链接A.Hayatoand贪心,不大想讲代码写的很丑voidsolve(){ vector<int>a; intn,x; cin>>n; a.push_back(0); for(inti=1;i<=n;++i)......
  • Codeforces Global Round 2
    A  题解:枚举每个颜色的头和尾然后最大化另一端upd:赛时麻烦了,显然答案的一端为头或者尾,枚举另一端即可。#include<bits/stdc++.h>usingnamespacestd;typed......
  • 1.30 vp Codeforces Round #846 (Div. 2)
    A-HayatoandSchool、题意给出长度为n的序列a,要求判断是否存在三个数之和为奇数,若有则输出YES且输出这三个数的下标,否则输出NO思路数字和为奇数的情况只有奇+偶,......
  • CF1787H Codeforces Scoreboard 题解
    鬼知道怎么会撞题的,甚至是没听过的OJ。首先不考虑对\(a_i\)取\(\max\),显然直接按照\(k\)降序排序最优。接下来考虑\(a_i\)的限制,如果取到了\(a_i\)一定放在最......
  • 1.29 vp Educational Codeforces Round 142 (Rated for Div. 2)
    A-GamingForces题意有n只怪兽,每个怪的血量是\(a_i\),有两种操作:1.直接消灭这只怪2.消灭两只血量为1的怪问最少需要多少次操作可以将怪全部杀死思路可以想到,操作二......
  • Codeforces Round #844 (Div. 1 + Div. 2, based on VK Cup 2022 - Elimination Roun
    CodeforcesRound#844(Div.1+Div.2,basedonVKCup2022-EliminationRound)[A-D]AParallelProjectionstandardinput/output1s,512MBBGoingt......
  • Codeforces Round #846 (Div. 2) B. GCD Partition
    B.GCDPartition参考题解链接:CodeforcesRound#846(Div.2)—Tutorial-Codeforces题意:给一个长度为n的序列,并将其分成连续的k块(k>1),得到序列......
  • Codeforces Round #847 (Div. 3)
    A.PolycarpandtheDayofPi先纯一下圆周率前30位,然后暴力就好了#include<bits/stdc++.h>usingstd::cin;usingstd::cout;usingstd::string;intread(){...}......
  • Codeforces Round #847 (Div. 3) ABCDE
    url:Dashboard-CodeforcesRound#847(Div.3)-CodeforcesA.PolycarpandtheDayofPi题意:判断给的字符串前多少位跟PI一样思路:打个表,然后遍历一下即可,遇......
  • Codeforces Global Round 1
    A  题解:倒叙枚举即可。1#include<bits/stdc++.h>2usingnamespacestd;34typedeflonglongll;5constllN=1e6+3;6llb,k,a[N];7voidSolv......