Team Formation---zoj3870(异或)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518
题意就是有n个数,如果满足a^b > MAX(a, b),就算一种组合,问n个数之间这样的组合有多少个;
可以发现,如果要让一个数增大,只要该数化为二进制后的出现0的位置跟1异或就会变大,
同时需要满足另一个数的最高位为该数出现0位置的位数,
如10可以跟1异或变为11 ,100可以跟10、11、1异或分别变为110,111,101,而101只能跟两位的进行异或,
因为它的0出现的位置为第二位,最后求和就行了。
cnt[i]代表a数组都转换成二进制数后最高位所在位置i为1的数的个数;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std; #define N 100010
int a[N];
int main()
{
int T, b[], cnt[], ans, n;
scanf("%d", &T);
while(T--)
{
memset(a, , sizeof(a));
memset(cnt, , sizeof(cnt));
scanf("%d", &n);
for(int i=; i<n; i++)
scanf("%d", &a[i]);
sort(a, a+n);
ans=;
for(int i=; i<n; i++)
{
int j=;
while(a[i])
{
b[j++] = a[i]%;
a[i]/=;
}
for(int k=; k<j; k++)
{
if(b[k]==)
ans+=cnt[k];///表示首位是这个位置的并且为1的,0与之异或一定变大;
}
cnt[j-]++;///让该位置为1的个数加1;
}
printf("%d\n", ans);
}
return ;
}
Team Formation---zoj3870(异或)的更多相关文章
- ZOJ - 3870 Team Formation(异或)
题意:给定N个数,求这N个数中满足A ⊕ B > max{A, B})的AB有多少对.(A,B是N中的某两个数) 分析: 1.异或,首先想到转化为二进制. eg:110011(A)和 1(B)- ...
- ZOJ3870 Team Formation
/** Author: Oliver ProblemId: ZOJ3870 Team Formation */ /* 思路 1.异或运算,使用^会爆,想到二进制: 2.我们可以试着从前往后模拟一位一位 ...
- 位运算 ZOJ 3870 Team Formation
题目传送门 /* 题意:找出符合 A^B > max (A, B) 的组数: 位运算:异或的性质,1^1=0, 1^0=1, 0^1=1, 0^0=0:与的性质:1^1=1, 1^0=0, 0^ ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- Team Formation(思维)
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- 2015 浙江省赛B Team Formation (技巧,动归)
Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...
- Zoj 3870——Team Formation——————【技巧,规律】
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- ZOJ 3870:Team Formation(位运算&思维)
Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- ZOJ 3870 Team Formation 贪心二进制
B - Team Formation Description For an upcoming progr ...
随机推荐
- lseek函数与文件空洞
在UNIX/LINUX系统中,文件位移量可以大于文件的当前长度,这种情况下向文件中写入数据就会产生文件空洞(hole),这些没写入数据的文件空洞部分默认会被0填满.虽然这些文件空洞并没有实际的数据,但 ...
- win7 自带计算机(for programmer)
打开win7的Accessories, 看到Calculator, 点击打开计算器. 可以看到32位的2进制代码:
- tagVARIANT、VARIANT、_variant_t和COleVariant
tagVARIANT是一个结构体struct: C++ Code: tagVARIANT 123456789101112131415161718192021222324252627282930313 ...
- Java程序员面试技巧
Java 程序员面试技巧 对于每一个求职者,有一份优秀的简历是很必要的,企业通过简历的筛选,会给予求职者面试的机会.然而,很多求职者就是在面试过程中与钟情的工作失之交臂.如何在面试中取得成功呢?“细节 ...
- Python 数据类型:数值
数值类型分为:整型 .长整型 .浮点型 .复数型 整型示例: In [1]: a = 100 # 整型也就是整数类型 In [2]: type(a) # 整型的英文缩写为int Out[2]: int ...
- Unity3D自己常用代码
常需要,常查找! 自己记录下! 1. var ray = Camera.main.ScreenPointToRay(Input.mousePosition); //GameObject.CreateP ...
- iPhone较为基础的代码片段
Iphone代码片段导航 1.给UITableViewController添加ToolBar. self.navigationController.toolbarHidden = NO; //默认是隐 ...
- UITableView取消选中颜色、常用操作
UITableView取消选中颜色.常用操作 使用空白view取代cell - (UITableViewCell *)tableView:(UITableView *)tableView cell ...
- ubuntu安装TexturePicker
TexturePacker网页:https://www.codeandweb.com/texturepackerTexturePacker下载页面:https://www.codeandweb.com ...
- poj_2739 尺取法
题目大意 给定一个数字N,N可能由1个或多个连续的素数求和得到,比如41 = 2+3+5+7+11+13, 41 = 11+13+17, 41 = 41.求出对于N,所有可能的组合形式. 题目分析 先 ...