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;
    }
  • 相关阅读:
    no-return-assign (Rules) – Eslint 中文开发手册
    CSS 字体图标
    CSS 元素的显示与隐藏
    CSS 定位
    CSS 清除浮动
    CSS 浮动
    java 运算符
    Java 初识
    CSS3 完善盒模型
    CSS 盒子模型
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5802951.html
Copyright © 2011-2022 走看看