zoukankan      html  css  js  c++  java
  • 快乐的一天从AC开始 | 20210809 | CF1554C

    题目链接

    每日吐槽

    昨天组长分了个需求,今天再去问组长已经做好了。。。

    心路历程

    二进制

    思路

    (n oplus x = y Rightarrow n oplus x oplus x oplus y = y oplus x oplus y Rightarrow n oplus y = x)

    然后题目是求(MEX{ n oplus x | 0 le x le m }),那么就有(MEX = min{ x | n oplus x > m})

    然后就从高位开始贪心,能填0就填0。

    完事。

    AC代码

    #include <bits/stdc++.h>
    using namespace std;
    #ifdef BACKLIGHT
    #include "debug.h"
    #else
    #define debug(...)
    #endif
    
    const int N = 1e5 + 5;
    
    void solve(int Case) {
      int n, m;
      scanf("%d %d", &n, &m);
    
      int k = 0;
      /**
       * n ^ x = mex
       * n ^ mex = x
       * 0 <= x <= m
       * k = min{x | n ^ x > m}
       * */
      int mask = 0;
      for (int i = 30; i >= 0; --i) {
        mask += (1 << i);
        if (n & (1 << i))
          ;
        else {
          int ma = (k ^ (n & mask)) + ((1 << i) - 1);
          if (ma > m)
            ;
          else
            k |= (1 << i);
          debug(k, ma, k ^ n, m);
        }
      }
      printf("%d
    ", k);
    }
    
    int main() {
    #ifdef BACKLIGHT
      freopen("a.in", "r", stdin);
    #endif
      int T = 1;
      scanf("%d", &T);
      for (int t = 1; t <= T; ++t) solve(t);
      return 0;
    }
    
  • 相关阅读:
    [机器人仿真软件(一)]V-REP与MATLAB进行通讯的方法
    TCP接收非法数据0xFFF4FFFD06的问题
    std::numeric_limits::epsilon
    linux 设置默认网关
    更换pip源
    实时屏幕传输
    安装node
    window 添加服务
    数据集格式
    jupyter 设置密码
  • 原文地址:https://www.cnblogs.com/zengzk/p/15121654.html
Copyright © 2011-2022 走看看