zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第四场)- triples I

    思维

    如果只有两个二进制位是1且不是3的倍数显然没有答案,我们只考虑两个以上的情况。

    • 若a mod 3=1:
    • 如果a中的二进制位有至少两个mod 3=1的,设它们为p和q,我们取{a-p,a-q}即可。
    • 如果a中的二进制位有恰好一个mod 3=1的,那么设mod 3=1的这个位为p,mod 3=2 的某个位为q,我们取{a-p,p+q}即可。
    • 如果a中的二进制位没有mod 3=1的,那么假设有三个mod 3=2的位p,q,r,我们取{a- p-q,p+q+r}即可。
    • 若a mod 3=2只需把上面的讨论中1与2互换即可,是完全对称的。
    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FastIn ios::sync_with_stdio(false), cin.tie(0)
    using namespace std;
    typedef long long LL;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)){
            w |= ch == '-', ch = getchar();
        }
        while(isdigit(ch)){
            ret = (ret << 3) + (ret << 1) + (ch ^ 48);
            ch = getchar();
        }
        return w ? -ret : ret;
    }
    inline int lcm(int a, int b){ return a / __gcd(a, b) * b; }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    
    int main(){
    
        int _;
        LL n;
        for(scanf("%d", &_); _; _ --){
            scanf("%lld", &n);
            if(n % 3 == 0){
                printf("1 %lld
    ", n);
                continue;
            }
            vector<LL> a, b, c;
            LL x = n;
            while(x) a.push_back(x & 1), x >>= 1;
            LL val = 1;
            for(int i = 0; i < a.size(); i ++){
                if(a[i]){
                    if(val % 3 == 1) b.push_back(val);
                    if(val % 3 == 2) c.push_back(val);
                }
                val <<= 1;
            }
            if(n % 3 == 1){
                if(b.size() >= 2) printf("2 %lld %lld
    ", n - b[0], n - b[1]);
                else if(b.size() == 1) printf("2 %lld %lld
    ", n - b[0], b[0] + c[0]);
                else printf("2 %lld %lld
    ", n - c[0] - c[1], c[0] + c[1] + c[2]);
            } else{
                if(c.size() >= 2) printf("2 %lld %lld
    ", n - c[0], n - c[1]);
                else if(c.size() == 1) printf("2 %lld %lld
    ", n - c[0], c[0] + b[0]);
                else printf("2 %lld %lld
    ", n - b[0] - b[1], b[0] + b[1] + b[2]);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    Exploratory Undersampling for Class-Imbalance Learning
    Dynamic Programming
    Learning in Two-Player Matrix Games
    IELTS
    A Brief Review of Supervised Learning
    测试下载
    [.net基础]访问修饰符
    [随记][asp.net基础]Page_Load和OnLoad
    第一份工作经历
    JForum2.1.9 安装过程
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11260838.html
Copyright © 2011-2022 走看看