链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#problem/I   (密码:0817)

题目大意:从n个数中取2个数,问有多少种方法取的两个数的异或大于两个数的最大数
思路:如果x的最高位i位是1,y的位是0,且y比x大,i不是y的最高位,异或后这一位变成1,且yi位以前的1也可以保存,则异或后肯定比两个数的最大值还大

先把数组用快排从大到小排一下序, 再把每个数转分别换为二进制,在二进制中是 0 的就在相应的位置加 1, 另外如果首位是 1 的话,就把 sum(最后求的值) 加上相应位置上的值

举个例子:

5

1 2 3 4 5

快排后是: 5 4 3 2 1

对应的二进制是:

0  0  0  0

1  0  1  b[1]++;

1  0  0  b[1]++,  b[0]++;

1  1  sum += b[1];

1  0  b[0]++,  sum += b[1];

1  sum += b[0];

比赛的时候,我没看这题,一直是队友们在做,我也不知道是什么意思,学长在结束给我们讲的时候,刚开始没懂什么意思,因为我不知道题意,没敢乱插话, 但是听他们说了一会儿,懂题意了,学长也很认真的讲了,知道了这题的思路,现在实现一下,是关于二进制的东西,接触的不多,觉得都很神奇,另外自己懂的太少了,还有一定要把深搜好好练练!!!

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std; #define N 100005 int cmp(int a, int b)
{
return a>b;
} int main()
{
int t;
scanf("%d", &t); while(t--)
{
int n, i, b[]={}, x[N]={}, sum=; scanf("%d", &n); for(i=; i<=n; i++)
scanf("%d", &x[i]); sort(x+, x+n+, cmp); for(i=; i<=n; i++)
{
int j=, a[]={};
while(x[i])
{
a[++j] = x[i]%;
x[i] /= ;
}
if(a[j]) sum += b[j]; while(j)
{
if(!a[j])
b[j]++;
j--;
}
} printf("%d\n", sum);
}
return ;
}

(二进制 异或)Team Formation --ZOJ --3870的更多相关文章

  1. ZOJ 3870 Team Formation 贪心二进制

                                                    B - Team Formation Description For an upcoming progr ...

  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^ ...

  3. Zoj 3870——Team Formation——————【技巧,规律】

    Team Formation Time Limit: 3 Seconds      Memory Limit: 131072 KB For an upcoming programming contes ...

  4. ZOJ 3870:Team Formation(位运算&思维)

    Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  6. ZOJ3870 Team Formation

    /** Author: Oliver ProblemId: ZOJ3870 Team Formation */ /* 思路 1.异或运算,使用^会爆,想到二进制: 2.我们可以试着从前往后模拟一位一位 ...

  7. Team Formation(思维)

    Team Formation Time Limit: 3 Seconds      Memory Limit: 131072 KB For an upcoming programming contes ...

  8. 2015 浙江省赛B Team Formation (技巧,动归)

    Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...

  9. 第十二届浙江省大学生程序设计大赛-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 ...

随机推荐

  1. How to Pronounce the Word SOMETHING

    How to Pronounce the Word SOMETHING Share Tweet Share Something tells me you’re going to like this v ...

  2. hibernate中.常见的hql查询语句

    hql是非常有意识的被设计为完全面向对象的查询 基本规则: 1.hql语法类似于sql,但它后面跟的不是表名和字段名,而是类名和属性名 2.hql大小写不敏感.但是设计java类名,包名,属性名时大小 ...

  3. MySql初步II

    [MySql初步II] 1.Order By 你可以使用 ASC 或 DESC 关键字来设置查询结果是按升序或降序排列. 默认情况下,它是按升排列. 实例: 2.Join语法 Join不是一个关键字 ...

  4. Windows平台下Flutter安装,配置,初运行。

    Flutter是什么?他是谷歌根据Dark语言开源的跨平台开发依赖.和目前比较火的Reactive Native一样,一套代码能够实现两个不同平台的App.那么为什么要介绍Flutter而不是在国内大 ...

  5. Animation.wrapMode循环模式

    WrapMode.Default:从动画剪辑中读取循环模式(默认是Once). WrapMode.Once:当时间播放到末尾的时候停止动画的播放. WrapMode.Loop:当时间播放到末尾的时候重 ...

  6. .net使用httpHandler添加图片防盗链

    .net使用httpHandler添加图片防盗链1. 配置web.config: <!--图片添加水印的配置--> <httpHandlers> <add verb=&q ...

  7. Ubuntu安装libevent

    背景: 版本: libevent 2.1.6beta linux下: 按照github官方做法: $ sudo apt-get install openssl $ mkdir build && ...

  8. swift UICollectionView使用

    方法1:创建 的时候注册 layout /// 时间view private lazy var timeCollectionV: UICollectionView = { 1.直接注册 并设置好 UI ...

  9. iOS 基于MVC设计模式的基类设计

    iOS 基于MVC设计模式的基类设计 https://www.jianshu.com/p/3b580ffdae00

  10. [leetcode]163. Missing Ranges缺失范围

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, up ...