zoukankan      html  css  js  c++  java
  • [构造]triples I

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

    来源:牛客网

    题目描述

    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.

    输入描述:

    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.

    输出描述:

    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.
    示例1

    输入

    复制
    2
    3
    7

    输出

    复制
    1 3
    2 3 6

    说明

    3=3, (3|6)=7

    备注:

    1≤T≤1051 leq T leq 10^51T105, 1≤a≤10181 leq a leq 10^{18}1a1018.

    思路:

    AC代码:

    #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
    ",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
    ",a-p,a-q);
                }
                else if(v[1].size()==1){
                    ll p=v[1][0],q=v[2][0];
                    printf("%lld %lld
    ",a-p,p+q);
                }
                else{
                    ll p=v[2][0],q=v[2][1],r=v[2][2];
                    printf("%lld %lld
    ",a-p-q,p+q+r);
                }
            }else{
                if(v[2].size()>=2){
                    ll p=v[2][0],q=v[2][1];
                    printf("%lld %lld
    ",a-p,a-q);
                }
                else if(v[2].size()==1){
                    ll p=v[2][0],q=v[1][0];
                    printf("%lld %lld
    ",a-p,p+q);
                }
                else{
                    ll p=v[1][0],q=v[1][1],r=v[1][2];
                    printf("%lld %lld
    ",a-p-q,p+q+r);
                }
            }
        }
        }
        return 0;
    }
    View Code
     
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    C#使用BouncyCastle操作国密SM3
    Win10 2004种子
    Excel对比两列数据,找到重复项
    CentOS7 + frp远程访问内网Windows电脑
    Docker on Mac OS
    MySQL5.6中查询多边形包含点情况(ST_Contains、ST_Within)
    SQL查询表的所有字段名
    清除文本中Html的标签
  • 原文地址:https://www.cnblogs.com/lllxq/p/11256345.html
Copyright © 2011-2022 走看看