ZOJ 3870 Team Formation(异或运算)
来源:互联网 发布:宽带网络那家好 编辑:程序博客网 时间:2024/09/21 08:51
题意:给出n个数,其中两个数的异或能大于他们本身。。
好气啊aaa,思路都对了,可惜没弄出来,,不难发现换成二进制后,某个数的最高位在其他数对应的数位为0的话,肯定比这两个数要大。。只要先储存下所有数的位数QAQ~~,然后再循环判断后面位数为0的情况。。
#include "string"#include "iostream"#include "cstdio"#include "cmath"#include "set"#include "queue"#include "vector"#include "cctype"#include "sstream"#include "cstdlib"#include "cstring"#include "stack"#include "ctime"#include "algorithm"#define pa pair<int,int>#define Pi M_PI#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLusing namespace std;typedef long long LL;const int M=30005;int a[M], bit[50]; // bit[i]表示有多少个数的最高位的1在第i位上void solve(int x) //哭晕 存储最高位{ int l = 31; while(l >= 0) { if(x & (1<<l)) { bit[l]++; return ; } l--; } return ;}int main(){ int T, n; scanf("%d", &T); while(T--) { scanf("%d", &n); memset(bit, 0, sizeof(bit)); for(int i = 0; i < n; i++) { scanf("%d", &a[i]); solve(a[i]); } int ans = 0; for(int i = 0; i < n; i++) { int l = 31; while(l >= 0) { if(a[i] & (1<<l)) break; l--; } while(l >= 0) { if(!(a[i] & (1<<l))) ans += bit[l]; l--; } } 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(异或运算),zoj3870
- 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(数学,位运算)
- zoj--3870--Team Formation(位运算好题)
- ZOJ 3870 Team Formation 位运算
- zoj 3870 Team Formation 位运算
- 黑马程序员——C语言(scanf函数、基本运算、流程控制)总结
- ARM汇编嵌套中断处理
- JSP:请求数据和请求本身的一些信息
- 常用数据库的驱动类/URL/默认端口
- 天声人語 20150426
- ZOJ 3870 Team Formation(异或运算)
- Pig
- HDU1358 Period【KMP】
- 日经春秋 20150426
- 初学Linux中进程调度与进程切换过程
- 三层架构学习总结
- 4.26学习内容 //todo注释的作用
- 黑马程序员---Java基础-----泛型和Map集合
- 英语总结系列(四):寻觅激励自我之道