Codeforces 702B. Powers of Two
来源:互联网 发布:ui需要哪些软件 编辑:程序博客网 时间:2024/06/01 08:19
题目连接:http://www.codeforces.com/problemset/problem/702/B
题意:给定n个数,判断有多少个数对(i, j)满足存在x且
想法:由于
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <vector>#include <cmath>typedef long long ll;const int MAXN = 100000 + 10;int a[MAXN];int main(){ std::ios::sync_with_stdio(false); int n; while(std::cin >> n){ for(int i = 0; i < n; ++i){ std::cin >> a[i]; } if(n == 1){ puts("0"); continue; } std::sort(a, a + n); ll ans = 0;//可能会超int int k = log(a[n - 1] + a[n - 2]) / log(2) + 1; for(int i = 0; i < n; ++i){ for(int j = 0; j <= k; ++j){ int t = (1 << j) - a[i]; if(t > 0){ int l = std::lower_bound(a + i + 1, a + n, t) - a; int r = std::upper_bound(a + i + 1, a + n, t) - a; if(r > l){ ans += r - l; } } } } std::cout << ans << std::endl; } return 0;}
0 0
- Codeforces 702B - Powers of Two
- codeforces-702B-Powers of Two
- CodeForces 702B Powers of Two
- Codeforces 702B. Powers of Two
- codeforces 702B - Powers of Two
- Codeforces 702 B. Powers of Two(二分)
- CodeForces 702B Powers of Two(二分)
- 【CodeForces】702B - Powers of Two(二分)
- 【Codeforces】-702B-Powers of Two(二分)
- CodeForces 702B: Powers of Two(遍历、穷举)
- coderforces 702B - Powers of Two(二分)
- Educational Codeforces Round 15 B. Powers of Two
- Educational Codeforces Round 15, problem: (B) Powers of Two
- Educational Codeforces Round 15 B. Powers of Two (数学)
- Educational Codeforces Round 15 B Powers of Two
- Libgdx powers of two
- CodeForces702B Powers of Two
- codeforces 305 C. Ivan and Powers of Two
- 如何在PHP中防止SQL注入?
- 优秀程序员:分享、创新、交流、实践
- Flex 那些坑
- 常用jQuery操作
- [推荐] ecshop后台 listTable.js修改 搜索页面中的下一页 无效
- Codeforces 702B. Powers of Two
- c语言编译过程(转)
- Activiti源码分析
- poj 3020 --最小路径覆盖
- HSL to RGB
- Java基础学习总结(55)——java8新特性:stream
- ubuntu 更新系统后不能启动桌面
- Obj与mtl 3D文件格式详解
- mysql函数大全