CF1031B Curiosity Has No Limits(结论+枚举)

简介: CF1031B Curiosity Has No Limits(结论+枚举)

原题链接

思路:

有个公式是:

a&b+a∣b=a+b

这样我们就可以枚举第一个数并且结合a,b数组推出数组的下一个数,判断是否合法。

代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
#define I_int ll
inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a, ll b, ll p)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
const int inf = 0x3f3f3f3f;
#define PI acos(-1)
const double eps = 1e-8;
const int maxn =1e5+7;
int a[maxn],b[maxn],n,t[maxn];
int main(){
  n=read;
  rep(i,1,n-1) a[i]=read;
  rep(i,1,n-1) b[i]=read;
  for(int i=0;i<=3;i++){
    t[0]=i;
    bool flag=1;
    for(int j=1;j<n;j++){
      t[j]=a[j]+b[j]-t[j-1];
      if(a[j]!=(t[j]|t[j-1])||b[j]!=(t[j]&t[j-1])){
        flag=0;break;
      }
    }
    if(flag){
      puts("YES");
      for(int j=0;j<n;j++) cout<<t[j]<<" ";
      return 0;
    }
  }
  puts("NO");
  return 0;
}
目录
相关文章
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
3328 0
Online Judge System 中术语含义: OJ、AC、WA、TLE、OLE、MLE、PE、RE、CE
|
1月前
|
监控
第三十七章 使用 ^PROFILE 监控例程性能 - ^PROFILE 示例
第三十七章 使用 ^PROFILE 监控例程性能 - ^PROFILE 示例
27 0
|
1月前
|
监控 程序员
第三十六章 使用 ^PROFILE 监控例程性能 - Using ^PROFILE
第三十六章 使用 ^PROFILE 监控例程性能 - Using ^PROFILE
21 0
|
7月前
|
安全 网络安全 开发工具
如何修改/etc/security/limits.conf 一个进程能打开的最大文件数 1024 为 自己期望的数字
如何修改/etc/security/limits.conf 一个进程能打开的最大文件数 1024 为 自己期望的数字
114 0
|
9月前
|
机器学习/深度学习
CF1288A Deadline(枚举)
CF1288A Deadline(枚举)
31 0
初学算法之枚举---拨钟问题
初学算法之枚举---拨钟问题
LeetCode 1346. 检查整数及其两倍数是否存在 Check If N and Its Double Exist
LeetCode 1346. 检查整数及其两倍数是否存在 Check If N and Its Double Exist
|
人工智能 BI
CF761D Dasha and Very Difficult Problem(构造 思维)
CF761D Dasha and Very Difficult Problem(构造 思维)
60 0
|
语音技术 网络架构 Windows
CF1560 E. Polycarp and String Transformation(思维 枚举)
CF1560 E. Polycarp and String Transformation(思维 枚举)
62 0
枚举讲解及应用场景,应用要求,,使用枚举和#define的比较
枚举讲解及应用场景,应用要求,,使用枚举和#define的比较
86 0