ZOJ 3870 Team Formation
2016-05-08 23:17
363 查看
题目链接:
http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3870题解:
如果x xor y>max(x,y),那么就会有x和y的最高位不同(二进制表示),并且对于最高位小的那个数的最高位的位置,最高位大的那个数在相同的位置应为0.代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; const int maxn = 1e5 + 10; int n; int arr[maxn]; //cnt[i]表示最高位为i的数有多少个 int cnt[32]; void init() { memset(cnt, 0, sizeof(cnt)); } int main() { int tc; scanf("%d", &tc); while (tc--) { init(); scanf("%d", &n); for (int i = 0; i<n; i++) { scanf("%d", &arr[i]); for (int j = 30; j >= 0; j--) { if ((1 << j)&arr[i]) { cnt[j]++; break; } } } LL ans = 0; for (int i = 0; i<n; i++) { int j; for (j = 30; j >= 0; j--) { if ((1 << j)&arr[i]) { break; } } for (j -= 1; j >= 0; j--) { if (((1 << j)&arr[i]) == 0) { ans += cnt[j]; } } } printf("%lld\n", ans); } return 0; }
相关文章推荐
- 世界的本质是旋转(1)复平面与欧拉公式
- input输入密码回车自动提交数据
- js实现跨域(jsonp, iframe+window.name, iframe+window.domain, iframe+window.postMessage)
- python 字符串填充、补全、对齐,填充0.
- 为我妈写的自动统计的VBA程序
- 将tomcat内部默认日志方式改为Log4j未成功的记录
- Linux学习之文件搜索命令
- 逆向方面学习实践安排
- 5月8日 例:投票
- 2016.05.09~2016.05.15周计划、
- 20145301实验五 Java网络编程及安全
- maven环境变量配置
- Jboss5.1类加载及配置文件读取解密
- nm可以看静态库, 但ldd不可以
- 重写equal()时为什么也得重写hashCode()之深度解读equal方法与hashCode方法渊源
- test extjs
- SpringMVC注解版解析不同格式的JSON串
- Give some advice on how to learn html,css,and javascript for c developers
- CUDA学习笔记二
- 自制小游戏,(根据java书进行改进的)