E. Vlad and a Pair of Numbers
1.B. Rudolf and 1212.C. Rudolf and the Ugly String3.A. Rudolf and the Ticket4.D. Rudolf and the Ball Game5.G. Rudolf and Subway6.C. Choose the Different Ones!7.B. Following the String8.E. Klever Permutation9.D. Find the Different Ones!10.B. YetnotherrokenKeoard11.C. Removal of Unattractive Pairs12.D. Jumping Through Segments13.E. Good Triples14.F. Shift and Reverse15.C. Nikita and LCM16.B. Prefiquence
17.E. Vlad and a Pair of Numbers
18.D. XOR Construction19.C. Non-coprime Split20.D. Divide and Equalize21.E. Block Sequence22.D. In Love23.C. Theofanis' Nightmare24.D. Yet Another Monster Fight25.C. Count Triangles26.E. Count Paths27.Collecting Numbers II28.C. Even Subarrays29.C. Perform Operations to Maximize Score30.F. Color Rows and Columns31.C. To Become Max题解
首先,我们知道异或运算是无进位相加,那么a^b=x我们不妨先让a=x,b=0;而a,b其余二进制位上要么同为0,要么同为1。接下来,根据题意a+b=2x,我们可知我们同时为a,b加上x/2。此时再判断a^b是否等于x即可。
code
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int t; cin>>t; while (t--){ ll x; ll a,b; cin>>x; a=x/2; b=x+x-a; if ((a^b)==x) cout<<a<<" "<<b<<endl; else cout<<-1<<endl; } return 0; }
合集:
codeforces
分类:
刷题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?