[Configuration] triples I

Links: https://ac.nowcoder.com/acm/contest/884/D?&headNav=acm&headNav=acm

Source: Cattle-off network

Title Description

Doctor Elephant is testing his new program: output the bitwise or of the numbers inputed.
He has decided to input several multiples of 3 and the output of the program should be his favorite number  aaa.
Because he is lazy, he decided to input as few numbers as possible. He wants you to construct such an input for every  aaa he chose.
It's guaranteed that for every  aaa in the input there is such a solution. If there're multiple solutions you can output any.

Enter a description:

There're multiple test cases in a test file.
The first line contains a positive integer  T - the number of test cases.
In each of the following  T lines there is one positive integer aaa.

Output Description:

For each test case output a line. First you need to output the number of numbers in your input, and then you need to output these numbers, separating by spaces.
Example 1

Entry

copy
2
3
7

Export

copy
1 3
2 3 6

Explanation

3=3, (3|6)=7

Remarks:

1≤T≤1051 \ leq T \ leq 10 ^ 5 1 T 1 0 5,  1≤a≤10181 \ leq a \ leq 10 ^ {18} 1 a 1 0 1 8. 

思路:

AC Code:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

vector<ll> v[5];

void init(ll a){
  ll now=1;
  while(a){
    if(a&1) v[now%3].push_back(now);
    now<<=1;
    a>>=1;
  }
}

int main()
{
    ll t;scanf("%lld",&t);
    while(t--){
    ll a;scanf("%lld",&a);
    for(ll i=0;i<3;i++) v[i].clear();
    if(a%3==0) printf("1 %lld\n",a);
    else{
        init(a);

        printf("2 ");
        if(a%3==1){
            if(v[1].size()>=2){
                ll p=v[1][0],q=v[1][1];
                printf("%lld %lld\n",a-p,a-q);
            }
            else if(v[1].size()==1){
                ll p=v[1][0],q=v[2][0];
                printf("%lld %lld\n",a-p,p+q);
            }
            else{
                ll p=v[2][0],q=v[2][1],r=v[2][2];
                printf("%lld %lld\n",a-p-q,p+q+r);
            }
        }else{
            if(v[2].size()>=2){
                ll p=v[2][0],q=v[2][1];
                printf("%lld %lld\n",a-p,a-q);
            }
            else if(v[2].size()==1){
                ll p=v[2][0],q=v[1][0];
                printf("%lld %lld\n",a-p,p+q);
            }
            else{
                ll p=v[1][0],q=v[1][1],r=v[1][2];
                printf("%lld %lld\n",a-p-q,p+q+r);
            }
        }
    }
    }
    return 0;
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/lllxq/p/11256345.html