2 solutions

  • 0
    @ 2025-3-24 16:33:09

    这个位运算是真的nb!

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<algorithm>
    #include<bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int N = 1e3+10;
    ll a[N][N],sum;
    int main()
    {
        // for(int i = 0;i < 32;i++)
        // {
        //     cout<<((i>>4) & 1) <<((i>>3) & 1)<<((i>>2) & 1)<<((i>>1) & 1)<<(i & 1)<<"\n";
        // }
        for(int i = 0;i < 32;i++)
        {
            bitset<5> b(i);
            cout<<b<<"\n";
        }
        return 0; 
    }
    
    
    • 0
      @ 2023-4-4 0:26:44

      利用位运算的性质求每一位上为0还是1

      #include <bits/stdc++.h>
      using namespace std;
      
      #define endl '\n'
      #define LL long long
      #define ph push_back
      #define INF 0x3f3f3f3f
      #define PII pair<int, int>
      
      int main(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr), cout.tie(nullptr);
      for(int i=0;i<=31;i++){
      for(int j=4;j>=0;j--){
      cout<<(i>>j&1);
      }
      cout<<endl;
      }
      
      return 0;
      }
      
      • 1

      Information

      ID
      1821
      Time
      1000ms
      Memory
      512MiB
      Difficulty
      2
      Tags
      # Submissions
      31
      Accepted
      22
      Uploaded By