zoukankan      html  css  js  c++  java
  • CF1072B Curiosity Has No Limits

    思路:

    对于序列t,只要第一个数确定了,后续的数也随之确定了。枚举四种情况即可。
    实现:

     1 #include <iostream>
     2 #include <vector>
     3 
     4 using namespace std;
     5 int a[200005], b[200005];
     6 int get(int t, int a, int b)
     7 {
     8     int ans = 0, cnt = 0;
     9     while (t || a || b)
    10     {
    11         int x = t & 1, y = a & 1, z = b & 1;
    12         if (x == 0 && y == 1 && z == 0) ans |= 1 << cnt;
    13         else if (x == 1 && y == 1 && z == 1) ans |= 1 << cnt;
    14         else if (x == 0 && y == 1 && z == 1) return -1;
    15         else if (x == 0 && y == 0 && z == 1) return -1;
    16         else if (x == 1 && y == 0 && z == 0) return -1;
    17         else if (x == 1 && y == 0 && z == 1) return -1;
    18         t >>= 1;
    19         a >>= 1;
    20         b >>= 1;
    21         cnt++;
    22     }
    23     return ans;
    24 }
    25 int main()
    26 {
    27     int n;
    28     while (cin >> n)
    29     {
    30         for (int i = 0; i < n - 1; i++) cin >> a[i];
    31         for (int i = 0; i < n - 1; i++) cin >> b[i];
    32         bool ok = false;
    33         for (int k = 0; k < 4; k++)
    34         {
    35             if (ok) break;
    36             vector<int> v;
    37             v.push_back(k);
    38             bool flg = true;
    39             for (int i = 0; i < n - 1; i++)
    40             {
    41                 int tmp = get(v.back(), a[i], b[i]);
    42                 if (tmp == -1) { flg = false; break; } 
    43                 v.push_back(tmp);
    44             }
    45             if (flg)
    46             {
    47                 cout << "YES" << endl;
    48                 for (auto it: v) cout << it << " ";
    49                 cout << endl;
    50                 ok = true;
    51             }
    52         }
    53         if (!ok) cout << "NO" << endl;
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    C# 反射
    jquery 循环绑定click的问题
    socket 编程
    EF code first出现错误:列名 Discriminator 无效
    C# 两个类是否继承关系
    C# MD5,hmacSHA1
    文件分块上传
    读写CSV到DataTable
    ajax 提交数组 泛型集合(嵌套集合)
    Json中Date映射到model
  • 原文地址:https://www.cnblogs.com/wangyiming/p/9833521.html
Copyright © 2011-2022 走看看