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;
    }
  • 相关阅读:
    request内置对象
    JSP页面、包含
    HTTP协议
    html简介
    数据访问层工具类
    数据运算
    可变于不可变对象分类
    有序 无序 的区别
    字符串方法
    day01_final
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5802951.html
Copyright © 2011-2022 走看看