zoukankan      html  css  js  c++  java
  • Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    题目连接:

    http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/D

    Description

    There are n distinct points on a coordinate line, the coordinate of i-th point equals to xi. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

    In other words, you have to choose the maximum possible number of points xi1,xi2,…,xim such that for each pair xij, xik it is true that |xij−xik|=2d where d is some non-negative integer number (not necessarily the same for each pair of points)

    Sample Input

    6
    3 5 4 7 10 12
    
    

    Sample Output

    3
    7 3 5
    
    

    题意

    给定一个集合,求最大子集,该子集内所有元素差都等于2的幂次。

    题解:

    假设a-b=2k,a-c=2i,i!=k时,b-c的值必不满足条件,所以最大子集最多只有三个元素

    代码

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int n;
    set<long long> s;
    int ans;
    vector<long long> v;
    
    int main() {
        cin >> n;
        for (int i = 0; i < n; i++) {
            long long x;
            cin >> x;
            s.insert(x);
        }
        for (auto i:s) {
            for (int o = 0; o < 33; o++) {
                int flag1 = s.count(i - (1 << o));
                int flag2 = s.count(i + (1 << o));
                if (flag1 && flag2) {
                    cout << 3 << endl << (i - (1 << o)) << " " << i << " " << (i + (1 << o)) << endl;
                    return 0;
                }
                else if (flag1) {
                    if (!v.size()) {
                        v.push_back(i);
                        v.push_back(i - (1 << o));
                    }
                }
                else if (flag2) {
                    if (!v.size()) {
                        v.push_back(i);
                        v.push_back(i + (1 << o));
                    }
                }
            }
        }
        if (v.size()) {
            cout << 2 << endl;
            for (auto i: v) cout << i << " ";
        }
        else cout << 1 << endl << *s.begin();
    }
    
  • 相关阅读:
    Visual Studio调试器项目设置
    Debug.Assert Everyone!
    WinDbg中的.natvis文件和类型模板
    已安装的.NET CLR版本之间的w3wp.exe崩溃WinDbg后期调试
    用于DLL注入的WinDbg扩展---!injectdll
    Wireshark中PIDs与网络包的关联
    又又一款抓dmp工具---ProcDump
    基于.NET框架版本在Windbg中加载sos的脚本
    未记录的WinDBG扩展命令---itoldyouso
    合并符号服务器
  • 原文地址:https://www.cnblogs.com/EDGsheryl/p/9153683.html
Copyright © 2011-2022 走看看