zoukankan      html  css  js  c++  java
  • D. Ehab the Xorcist

    题目链接:https://codeforces.com/contest/1325/problem/D

    想法:

    #pragma GCC optimize(3,"Ofast","inline")//O3优化
    #pragma GCC optimize(2)//O2优化
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <map>
    #include <stack>
    #include <set>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <iomanip>
    #include <time.h>
    #include <bitset>
    #include <cmath>
    #include <sstream>
    #include <iostream>
    #include <cstring>
    
    #define LL long long
    #define ls nod<<1
    #define rs (nod<<1)+1
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define INF 0x3f3f3f3f
    #define max(a,b) (a>b?a:b)
    #define min(a,b) (a<b?a:b)
    
    const double eps = 1e-10;
    const int maxn = 2e5 + 10;
    const int mod = 1e9 + 7;
    
    int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}
    using namespace std;
    
    LL dat[maxn];
    LL ans[maxn];
    
    int main() {
        ios::sync_with_stdio(0);
        LL u,v;
        cin >> v >> u;
        dat[0] = 1;
        for (int i = 1;i <= 64;i++)
            dat[i] = dat[i-1] * 2;
        if (v > u) {    // u 肯定要大于 v
            cout << -1 << endl;
            return 0;
        }
        u -= v;
        LL t = u;
        int cnt1 = 0,cnt2 = 0;
        while (t != 0) {
            cnt1++;
            t >>= 1;
        }
        while (v != 0) {   // 先处理出 v 
            ans[cnt2++] = v & 1;
            v >>= 1;
        }
        if (cnt1 < cnt2)  // 确保是位数
            cnt1 = cnt2;
        LL cnt = cnt1;
        while (cnt >= 0) {
            if (2ll * dat[cnt] <= u) {
                ans[cnt] += 2;
                u -= 2ll * dat[cnt];
            }
            cnt--;
        }
        if (u) {
            cout << -1 << endl;
            return 0;
        }
        LL maxx = 0;
        for (int i = 0;i <= cnt1;i++)
            maxx = max(maxx,ans[i]);
        cout << maxx << endl;
        for (int i = 1;i <= maxx;i++) {
            LL now = 0;
            for (int j = 0;j <= cnt1;j++) {
                if (ans[j]) {
                    ans[j] -= 1;
                    now += dat[j];
                }
            }
            cout << now << " ";
        }
        return 0;
    }
  • 相关阅读:
    推流当中自适应码率的策略
    使用python实现人脸检测<转载>
    acm.njupt 1001-1026 简单题
    fedora 系统安装后常用设置
    一个普普通通的计算机研究生找工作的感悟
    一个简单的爬虫程序
    HDU 1005 Number Sequence
    【StatLearn】统计学习中knn算法的实验(1)
    SQL描述(2)
    连续点击返回键,退出应用程序
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/12585044.html
Copyright © 2011-2022 走看看