思维+位运算
思路
可以看看这个博客: https://blog.csdn.net/weixin_45799835/article/details/118659049 我觉得写得挺好
至于后面的总结出来的表达式我认为不太好,这边建议通过真值表推导(但是这个真值表还是观察推导出来的)
x y f
0 0 0
1 1 0
0 1 0
1 0 1
可以通过真值表求得逻辑表达式:f=x&(~y),然后就直接用就行
自己还是只能想到一部分的思路就想不下去了
代码
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int t,b[N],c[N],n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
int y;
cin>>y;
if(i==1)
c[i]=y^0;
else
{
b[i]=c[i-1]&(~y);
c[i]=y^b[i];
}
}
for(int i=1;i<=n;i++)
cout<<b[i]<<" ";
cout<<endl;
}
return 0;
}