zoukankan      html  css  js  c++  java
  • CodeForces 702B Powers of Two

    简单题。

    开一个$map$记录一下每个数字出现了几次,那么读入的时候$f[a[i]]+1$。

    计算$a[i]$做出的贡献的时候,先把$f[a[i]]-1$,然后再枚举$x$,答案加上$f[{2^x} - a[i]]$。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar(); x = 0;while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();  }
    }
    
    const int maxn=100010;
    LL a[maxn],ans;
    map<LL,int>f;
    int n;
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]),f[a[i]]++;
        for(int i=1;i<=n;i++)
        {
            f[a[i]]--; LL sum=1;
            for(int j=0;j<=32;j++)
            {
                ans=ans+f[sum-a[i]];
                sum=sum*2;
            }
        }
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    Training: WWW-Robots
    Training: Stegano I
    Encodings: URL
    利用Nginx实现域名转发 不修改主机头
    C++删除目录和复制目录函数
    获取文件大小的函数
    日志打印函数
    拉起上级目录程序
    安卓TabHost页面
    有趣的人形时钟
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5802951.html
Copyright © 2011-2022 走看看