牛客 QQ4 游戏任务标记

Tag: 牛客腾讯题库 Posted on 2022-03-03 15:18:52 Edited on 2022-03-03 15:46:30 Views: 149

概述

https://www.nowcoder.com/practice/2f45f0ef94724e06a4173c91ef60781c

考察位运算。

位运算

  1. 设置右起第 n 位为 1:a = a | 1 << n
  2. 检查右起第 n 为是否为 1:(a >> n) % 2 == 1
#include <iostream>

using namespace std;

int main() {
    uint t[32] = {};
    int a, b;
    cin >> a >> b;
    if (a <=0 || a > 1024 || b <= 0 || b > 1024) {
        cout << -1;
    } else {
        int x = (a - 1) / 32;
        int y = (a - 1) % 32;
        t[x] = t[x] | 1 << y;
        int m = (b - 1) / 32;
        int n = (b - 1) % 32;
        int res = (t[m] >> n) % 2 == 1;
        cout << res;
    }
}

未经允许,禁止转载,本文源站链接:https://iamazing.cn/