ZOJ 3870 - Team Formation(数学)
来源:互联网 发布:狸猫组态软件 编辑:程序博客网 时间:2024/06/07 20:03
题目:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870
题意:
给出n个数,每次选出2个数,问一共有多少种选法使得两数异或后的值大于两个数的最大值。
思路:
对于一个数x,x的最高位0改为1时,且0前的数不变,则x比原来要大。
AC.
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e5+5;int a[maxn], bit[35];void deal(int n){ int x = 31; while(x >= 0) { if(n & (1<<x)) { bit[x] ++; return; } x--; } return;}int main(){ //freopen("in", "r", stdin); int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); memset(bit, 0, sizeof(bit)); for(int i = 0; i < n; ++i) { scanf("%d", &a[i]); deal(a[i]); } int ans = 0; for(int i = 0; i < n; ++i) { int x = 31; while(x >= 0) { if(a[i] & (1<<x)) break; x--; } while(x >= 0) { if(!(a[i] & (1<<x))) ans+=bit[x]; x--; } } printf("%d\n", ans); } return 0;}
0 0
- ZOJ 3870 Team Formation(数学)
- ZOJ 3870 - Team Formation(数学)
- ZOJ 题目3870 Team Formation(数学,位运算)
- [水+数学] zoj 3870 Team Formation
- ZOJ 3870 Team Formation
- ZOJ 3870 Team Formation
- ZOJ 3870 Team Formation
- zoj #3870:Team Formation
- ZOJ 3870 Team Formation
- ZOJ-3870-Team Formation
- ZOJ-3870 Team Formation
- ZOJ 3870 Team Formation(异或)
- ZOJ 3870 Team Formation(位运算)
- ZOJ 3870Team Formation(位运算)
- ZOJ - 3870 Team Formation (位运算)
- ZOJ 3870 Team Formation (二进制)
- ZOJ-3870 Team Formation(位运算)
- ♥ZOJ 3870-Team Formation【异或,数学】
- ADO.Net知识整理
- ios 分页显示
- IoC模式
- (1.4.10) 迅雷2014校园招聘笔试题
- CSS 入门
- ZOJ 3870 - Team Formation(数学)
- Qt 实现的文本编辑器
- MySql的基本语句操作
- DP·数位DP(2)
- 二分查找
- 利用反射技术修改类中的字段(成员变量的反射)
- Linux常用命令大全
- hihoCoder 1038 : 01背包
- 数据挖掘数据集下载搜集整理版