6 条题解

  • 5
    @ 2022-2-11 23:59:13

    本题太难了

    现在是2/12 0:08

    死磕了半天终于……还是没搞懂

    终于我想到了他——位运算

    用one代表只出现一次的数位,two代表出现了两次的数位,three代表出现了三次的数位.

    废话不多,上代码

    #include<bits/stdc++.h>
    using namespace std;
    int aa;
    int main(){
    	int n,one=0,two=0,three=0;
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>aa;
    		two^=(one&aa);
        	one^=aa;
        	three=~(one&two);
        	two&=three;
        	one&=three;
        }
        cout<<one;
    }
    

    小知识,大世界:

    假设如果 A = 60,且 B = 13,现在以二进制格式表示,它们如下所示:

    A = 0011 1100

    B = 0000 1101


    A&B = 0000 1100

    A|B = 0011 1101

    A^B = 0011 0001

    ~A = 1100 0011

    下表显示了C++C++支持的位运算符.假设变量AA的值为60,变量BB的值为13,则:

    & 如果同时存在于两个操作数中,二进制ANDAND运算符复制一位到结果中.(A & B)将得到 12,即为00001100

    ∣| 如果存在于任一操作数中,二进制 OROR 运算符复制一位到结果中.(A | B)将得到61,即为00111101

    ^ 如果存在于其中一个操作数中但不同时存在于两个操作数中,二进制异或运算符复制一位到结果中.(A ^ B)将得到49,即为00110001

     ~ 二进制补码运算符是一元运算符,具有"翻转"位效果,即0变成1,1变成0.(~A )将得到 -61,即为 1100 0011,一个有符号二进制数的补码形式

    <<<< 二进制左移运算符。左操作数的值向左移动右操作数指定的位数.A << 2将得到 240,即为11110000

    >>>> 二进制右移运算符.左操作数的值向右移动右操作数指定的位数.A >> 2将得到15,即为00001111

  • 2
    @ 2022-7-3 22:41:29
    #include <math.h>
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    int a[100];
    long long calc()
    {
        long long sum =0;
        for(int i = 0 ; i < 60 ; i++)
        {
            a[i] %= 3;
            if(a[i])
                sum += (1 << i);
        }
        return sum;
    }
    void f(long long x)
    {
        long long len = 0;
        while(x!=0)
        {
            if(x&1)
                a[len]++;
            len++;
            x/=2;
        }
    }
    int main()
    {
        long long n ;
        cin >> n;
        for(long long i = 0,x ; i < n ; i++)
        {
            scanf("%d",&x);
            f(x);
        }
        cout << calc() <<endl;
        return 0;
    }
    
    • 1
      @ 2026-11-22 20:09:50

      #include <math.h> #include <stdio.h> #include #include <string.h> #include using namespace std; int a[100]; long long calc() { long long sum =0; for(int i = 0 ; i < 60 ; i++) { a[i] %= 3; if(a[i]) sum += (1 << i); } return sum; } void f(long long x) { long long len = 0; while(x!=0) { if(x&1) a[len]++; len++; x/=2; } } int main() { long long n ; cin >> n; for(int i = 0,x ; i < n ; i++) { scanf("%d",&x); f(x); } cout << calc() <<endl; return 0; }

      • 0
        @ 2025-9-5 21:24:52
        #include<queue>
        #include<math.h>
        #include<stdio.h>
        #include<iostream>
        #include<vector>
        #include<iomanip>
        #include<string.h>
        #include<algorithm>
        #include<cmath>
        #include<cstdio>
        #include<utility>
        #include<cstring>
        #include<stack>
        #include<fstream>
        #include <sstream>
        #include<string>
        #include<stdlib.h>
        using namespace std;
        #define ll long long
        const int N = 1e6 + 10;
        const int INF = 0x3f3f3f3f;
        int aa;
        int main()
        {
            int n , one = 0 , two = 0 , three = 0;
            cin >> n;
            for ( int i = 1 ; i <= n ; i++ )
            {
                cin >> aa;
                two ^= ( one & aa );
                one ^= aa;
                three =~ ( one & two );
                two &= three;
                one &= three;
            }
            cout << one;
            return 0;
        }
        

        感谢huhe(小小苦力怕)http://temege.com/user/698

        • -1
          @ 2026-11-22 18:45:22
          #include<bits/stdc++.h>
          using namespace std;
          long long a[101],n,x,sum=0;
          int main(){
          	cin>>n;
          	for(int i=0;i<n;i++){
          		cin>>x;
          		long long len=0;
          		while(x!=0){
          			if(x&1) a[len]++;
          			len++;
          			x/=2;
          		}
          	}
          	for(int i=0;i<60;i++){
          		a[i]%=3;
          		if(a[i]) sum+=(1<<i);
          	}
          	cout<<sum;
          	return 0;
          }
          
          • -1
            @ 2026-4-26 10:52:41

            #include<bits/stdc++.h> using namespace std; int aa; int main(){ int n,one=0,two=0,three=0; cin>>n; for(int i=1;i<=n;i++){ cin>>aa; two^=(one&aa); one^=aa; three=~(one&two); two&=three; one&=three; } cout<<one; }

            • 1

            信息

            ID
            1224
            时间
            1000ms
            内存
            5MiB
            难度
            7
            标签
            递交数
            486
            已通过
            102
            上传者