ZOJ-3870-Team Formation
来源:互联网 发布:如网络中罕有受控源 编辑:程序博客网 时间:2024/05/19 06:35
点击打开题目链接
/*异或运算中 同0异1,要求得x = max(x1, x2),则应使得x1[pos] = 1&&x2[pos] = 0(pos为x1的最高位);*/#include <iostream>#include <cstring>#include <string>#include <algorithm>using namespace std;const int Max = 1e5 + 10;int a[Max];int bit[50];//最高位在当前位置的数的个数int f[Max];//对于数x的最高位的位置/*作用:寻找数x的最高位的位置pos,并累加bit[pos];*/void solve(int x,int i){int pos = 30;while(pos>=0){if(x&(1<<pos)){bit[pos] ++;f[i] = pos;return;}pos--;}}int main(){int T,n;cin>>T;while(T--){memset(bit,0,sizeof(bit));cin>>n;for(int i=0;i<n;i++){cin>>a[i];solve(a[i],i);}int sum = 0 ;for(int i=0; i<n; i++){int pos = f[i];while(pos>=0){if(!(a[i]&(1<<pos)))sum += bit[pos];pos--;}}cout<<sum<<endl;} 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 3870 Team Formation (数位统计问题)
- ZOJ 3870 Team Formation (异或运算)
- ZOJ 3870 Team Formation 位运算
- zoj 3870 Team Formation 位运算
- ZOJ Team Formation 3870【位运算】
- quickling解决方案
- struts2.0中struts.xml配置文件详解
- “J.U.C”:ReentrantLock之三unlock方法分析
- iOS计算两个时间的时间差
- 【转载】浅谈HTTP中Get与Post的区别
- ZOJ-3870-Team Formation
- JS内存泄漏排查方法-Chrome Profiles
- Elasticsearch入门1
- (继承)Problem A: Person类与Student类的关系
- C++Primer Plus(第六版) 第六章 第二题
- PAT_乙级_1002_筱筱
- md5.js(提交前加密)
- 题目1015:还是A+B
- 用户界面线程AfxBeginThread的使用