zoukankan      html  css  js  c++  java
  • Good Bye 2019 C. Make Good

    链接:

    https://codeforces.com/contest/1270/problem/C

    题意:

    Let's call an array a1,a2,…,am of nonnegative integer numbers good if a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am), where ⊕ denotes the bitwise XOR operation.

    For example, array [1,2,3,6] is good, as 1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6). At the same time, array [1,2,1,3] isn't good, as 1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3).

    You are given an array of length n: a1,a2,…,an. Append at most 3 elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.

    思路:

    想多了发现是sb题,让右边为0,加个左边就行了

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAXN = 1e5+10;
    
    int n;
    int a[MAXN];
    
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            cin >> n;
            LL ans = 0, sum = 0;
            for (int i = 1;i <= n;i++)
            {
                cin >> a[i];
                ans ^= a[i];
                sum += a[i];
            }
            if (ans*2 == sum)
                cout << 0 << endl << endl;
            else if (ans == 0)
            {
                cout << 1 << endl;
                cout << sum << endl;
            }
            else
            {
                sum += ans;
                cout << 2 << endl;
                cout << ans << ' ' << sum << endl;
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    HDU 2098 分拆素数和
    HDU 2034 *人见人爱A-B
    HDU 1236 排名(Microsoft_zzt)
    HDU 5702 Solving Order
    HDU 2033 人见人爱A+B
    HDU 2029 Palindromes _easy version
    HDU 2021 发工资咯:)
    HDU 2071 Max Num
    HDU 2039 三角形
    页面使用element-tree
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12122445.html
Copyright © 2011-2022 走看看