链接:

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. python语法学习之函数、类、模块

    Python中通过使用类(class)和对象(object)来实现面向对象(object-oriented programming,简称OOP)的编程. 面向对象编程的最主要目的是提高程序的重复使用性 ...

  2. [转载]百分之百自动登录2345王牌技术员联盟源代码(delphi)

    资源地址:http://download.csdn.net/detail/softlib/9670613

  3. How a non-windowed component can receive messages from Windows

    Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...

  4. Hibernate 的Ehache学习

    Hibernate默认二级缓存是不启动的,启动二级缓存(以EHCache为例)需要以下步骤: 1.添加相关的包: Ehcache.jar和commons-logging.jar,如果hibernate ...

  5. Openning SharePoint - 80 website gives HTTP 404 Error, The webpage cannot be found ! on SharePoint 2013

    ask: I tried to open the SharePoint - 80 throw Browse in IIS, but I get HTTP 404 Error (The webpage ...

  6. 关于EL表达式取值的问题

    EL表达式取值时,如果没有指定作用域,EL表达式会自动按照作用域的大小,从小到大依次去找;比如${s},会自动按照"pageContext,request,session,applicati ...

  7. Cannot create inner bean '(inner bean)#67f903b5' of typ

    严重: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error crea ...

  8. 无插件,无com组件,利用EXCEL、WORD模板做数据导出(一)

    本次随笔主要讲述着工作中是如何解决数据导出的,对于数据导出到excel在日常工作中大家还是比较常用的,那导出到word呢,改如何处理呢,简单的页面导出问题应该不大,但是如果是标准的公文导出呢,要保证其 ...

  9. vs2010下载Microsoft Visual Studio 2010 Express(vs2010中文版下载)速成官方合集正式版

    http://www.xiazaiba.com/html/1832.html VB.NET 2010 Express: 2KQT8-HV27P-GTTV9-2WBVV-M7X96VC++ 2010 E ...

  10. Django之ORM使用以及模板语言

    一.ORM版增删改查 1.ORM的语句 1.类名.objects.all()          --> 返回一个列表 2.类名.objects.filter()       --> 返回一 ...