当前位置:网站首页>Deltix Round, Summer 2021 D. Take a Guess(二进制计算常用性质汇总)
Deltix Round, Summer 2021 D. Take a Guess(二进制计算常用性质汇总)
2022-04-21 15:27:00 【合金Bunny酱】
洛谷链接:Take a Guess - 洛谷
题意看洛谷翻译
解法:需要用到一些二进制计算的性质,这些需要作为结论记住。
- a+b = (a|b) + (a&b)
- a+b = (a^b) + 2(a&b)
- a^b = (a|b) ^ (a&b)
本题可以用第1,2个性质解,依次询问a[1]和任意的a[i]相或和相与的值,得到和,最后再询问a[2]和a[3]两次,得到他们的和,就可以知道所有数字的值。
#include <bits/stdc++.h>
#define int long long
#define debug cout<<"!!!"<<endl;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define pii pair<int,int>
#define ls p<<1
#define rs p<<1|1
using namespace std;
const int N = 1e4+5;
int n,k,a[N];
inline void solve(){
cin>>n>>k; int x;
FOR(i,2,n){
cout<<"and 1 "<<i<<endl; cin>>x; a[i]+=x;
cout<<"or 1 "<<i<<endl; cin>>x; a[i]+=x;
}
int s23 = 0;
cout<<"and 2 3"<<endl; cin>>x; s23+=x;
cout<<"or 2 3"<<endl; cin>>x; s23+=x;
a[1] = (a[2]+a[3]-s23)/2;
FOR(i,2,n) a[i]-=a[1];
sort(a+1,a+n+1);
cout<<"finish "<<a[k]<<endl;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// freopen("input.txt","r",stdin);
int T; T=1; while(T--) solve();
}
版权声明
本文为[合金Bunny酱]所创,转载请带上原文链接,感谢
https://blog.csdn.net/bunny_1024/article/details/124310222
边栏推荐
- Jetpack compose uses custom operators to achieve the effect of drawing five pointed stars
- 【二分查找-简单】69. x 的平方根
- MySQL
- [introduction to machine learning] - Lesson 6 - Bayesian classifier
- Universal navigation: a concise and practical comprehensive navigation website
- Introduction to openlayers (II)
- 【C语言进阶】自定义类型:结构体,位段,枚举,联合
- AcWing 1854. 晋升计数(模拟)
- 全国降雨侵蚀力因子R值
- Dry goods | app control positioning of mobile app automation
猜你喜欢

OpenHarmony3.1 H264视频播放之路

GLASS:用于子图表示学习的 GNN 标签技巧

AcWing 1812. Square pasture (enumeration)
![[advanced C language] user defined type: struct, bit segment, enumeration, union](/img/c5/4f2756aaa642a17c322ea480987041.png)
[advanced C language] user defined type: struct, bit segment, enumeration, union

Universal navigation: a concise and practical comprehensive navigation website

机器学习方法创建可学习的化学语法,构建可合成的单体和聚合物

58页西门子机床行业数字化解决方案

OpenHarmony相机用户态驱动框架

产业园区数字孪生规划方案

OpenHarmony3. 1 H264 video playback Road
随机推荐
Login refactoring notes
[机器学习导论]——第六课——贝叶斯分类器
Page 92 group informatization planning scheme enterprise application integration solution
Solution de transformation de mot de données de 111 pages Fine Chemical Co., Ltd.
全国降雨侵蚀力因子R值
Web.xml文件详解
什么是电子邮箱地址?好用的电子邮箱注册申请
Mysql
[binary search - medium] 1498 Number of subsequences satisfying the condition
MySQL
[binary search - medium] 1855 Maximum distance of subscript alignment (need to review double pointer method)
Site intelligent solution
别紧张,就是聊聊软考
Smart public security QR code positioning alarm system development of mobile police app
企业邮箱如何申请?如何用手机号注册邮箱?
[Unity] error CS0433: The type ‘Task‘ exists in both Unity.Tasks,....
78页数字孪生+智慧楼宇解决方案
49页企业数字化转型案例及常用工具企业数字化转型思路
[binary search - simple] sword finger offer II 072 take a square root
What are the websites evaluated by app?