ZOJ 3870 Team Formation
来源:互联网 发布:邮件群发软件下载 编辑:程序博客网 时间:2024/05/19 22:44
题意:给出n个数,在其中任意挑出两个数进行异或,判断有多少种情况使得异或的值大于原数。
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518
思路:转化为二进制,对位进行拆分,求出每一位的0的个数a以及二进制位数b,输出sum(a*b)
注意点:无
以下为AC代码:
Run IDSubmit TimeJudge StatusProblem IDLanguageRun Time(ms)Run Memory(KB)User Name39450062015-04-26 18:38:13Accepted 3870C++0x380272luminus/* ************************************************# @Author : Luminous11 (573728051@qq.com)*# @Date : 2015-04-26 18:25:24*# @Link : http://blog.csdn.net/luminous11*********************************************** */#include <bits/stdc++.h>#define clr(a, v) memset( a , v , sizeof(a) )using namespace std;const double eps = 1e-10;const double pi = acos(-1.0);int num0[35];int num1[35];void calc ( int tmp ){int p = 1;while ( tmp ){if ( ( tmp & 1 ) == 0 ){num0[p] ++;}tmp >>= 1;p ++;}num1[p-1] ++;}int main(){//ios::sync_with_stdio ( false );int T;scanf ( "%d", &T );while ( T -- ){int n;scanf ( "%d", &n );memset ( num0, 0, sizeof ( num0 ) );memset ( num1, 0, sizeof ( num1 ) );int tmp;for ( int i = 0; i < n; i ++ ){scanf ( "%d", &tmp );calc ( tmp );}long long ans = 0;for ( int i = 0; i < 35; i ++ ){ans += (long long)num0[i] * (long long)num1[i];}printf ( "%lld\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
- 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【位运算】
- 分享测试自动化的19个教训
- 黑盒测试技术之等价类划分_软件测…
- 黑盒测试技术之等价类划分_软件测…
- 黑马程序员——java基础知识之其他对象和IO流(一)
- 黑盒测试技术之等价类划分_软件测…
- ZOJ 3870 Team Formation
- 黑盒测试技术之等价类划分_软件测…
- 黑盒测试之边界值分析、错误猜测
- 随堂记录
- 黑盒测试之边界值分析、错误猜测
- 二叉树的子结构
- C语言基础—关键字和标识符
- 黑盒测试之边界值分析、错误猜测
- 黑盒测试之边界值分析、错误猜测