1207E - XOR Guessing(思维+构造)

98 篇文章 3 订阅
本文详细介绍了如何解决Codeforces上的问题1207E。作者通过创建两个集合,分别处理前7位和后7位,并进行按位操作来找出答案。代码中使用了位运算技巧,先输出第一个集合,然后输入并获取答案,再输出第二个集合并获取另一个答案,最后组合两个答案的特定位得到最终结果。这个过程展示了如何在算法竞赛中高效地处理位操作问题。
摘要由CSDN通过智能技术生成

https://codeforces.com/problemset/problem/1207/E


思路:

14位,第一个集合,后7为全放0.

第二个集合,前7位放0.

对于询问得到的答案,取第一个的后7位,第二个的前7位。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void){
   vector<LL>v1;
   for(LL i=1;i<=100;i++){
       LL x=0;
       x<<7;
       x+=i;
       v1.push_back(x);
   }
   vector<LL>v2;
   for(LL i=1;i<=100;i++){
       LL x=0;
       x+=(i<<7);
       v2.push_back(x);
   }
   cout<<"? "<<endl;
   for(auto i:v1){
       cout<<i<<" ";
   }
   cout<<endl;
   LL num1;cin>>num1;
   cout<<"? "<<endl;
   for(auto i:v2){
       cout<<i<<" ";
   }
   cout<<endl;
   LL num2;cin>>num2;
   LL ans=0;
   for(LL i=7;i<=14;i++){
       ans+=(num1&(1<<i) );
   }
   for(LL i=0;i<7;i++){
       ans+=(num2&(1<<i) );
   }
   cout<<"! "<<ans<<endl;
   return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值