https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team

这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过。参考了:http://chasethered.com/2014/07/hackerrank-weekly-challenge-6-problem-1/

首先是转化成int32的数组,然后N^N的复杂度两两比较求bit数。求bit中1的个数有几种做法:

- x & (x - 1)
- Hamming weight的经典求法,基于树状累加:http://en.wikipedia.org/wiki/Hamming_weight
- 内存足够大可以查表得;

#include <iostream>
#include <vector>
#include <string>
using namespace std; int bitCount(unsigned int u) {
unsigned int uCount; uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
return ((uCount + (uCount >> 3)) & 030707070707) % 63;
} int main() {
int N;
int M;
cin >> N >> M;
vector<vector<int>> bm(N);
int len = (M - 1) % 32 + 1;
for (int i = 0; i < N; i++) {
bm[i].resize(len);
}
for (int i = 0; i < N; i++) {
string s;
cin >> s;
int k = -1;
for (int j = 0; j < M; j++) {
if (j % 32 == 0)
k++;
bm[i][k] *= 2;
bm[i][k] += (int) (s[j] - '0');
}
}
int topicCount = 0;
int teamCount = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int local = 0;
for (int k = 0; k < len; k++) {
unsigned int tmp = bm[i][k] | bm[j][k];
int count = bitCount(tmp);
local += count;
}
if (local > topicCount) {
topicCount = local;
teamCount = 1;
} else if (local == topicCount) {
teamCount++;
}
}
}
cout << topicCount << endl;
cout << teamCount << endl;
return 0;
}

  

*[hackerrank]ACM ICPC Team的更多相关文章

  1. ACM ICPC Team

    Link: https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807 def count_max_to ...

  2. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  5. 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)

    2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...

  6. Codeforces 890A - ACM ICPC 暴力

    A. ACM ICPCtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputst ...

  7. Codeforces Round #445 A. ACM ICPC【暴力】

    A. ACM ICPC time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  8. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

  9. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

随机推荐

  1. table总结insertRow、deleteRow

    表格有几行: var trCnt = table.rows.length;  (table为Id ) 每行有几列:for (var i=0; i<trCnt; i++)             ...

  2. mongodb 3.x WiredTiger存储优化测试

    http://pan.baidu.com/s/1sk8zekX 总结:1.使用WiredTiger引擎压缩比例约是MMAP引擎的12倍,2.从时间上看,此次测试100个线程并发,mongodb 3.2 ...

  3. js中(function(){…})()立即执行函数写法理解(转载oschina)

    ( function(){…} )()和( function (){…} () )是两种javascript立即执行函数的常见写法,最初我以为是一个括号包裹匿名函数,再在后面加个括号调用函数,最后达到 ...

  4. 11g RAC R2 之Linux DNS 配置

    在动手配置前,最好先了解下DNS的理论,以免犯不必要的错误.这都是被坑后的觉悟 -_-!!! Oracle 11g RAC 集群中引入了SCAN(SingleClientAccessName)的概念, ...

  5. VS2013中自动缩进和注释的快捷键

    自动缩进: ctrl +k 再 ctrl +f 注释: ctrl+k 再 ctrl +c 取消注释: ctrl+k 再 ctrl+u

  6. Using self-defined Parcelable objects during an Android AIDL RPC / IPC call

    Using self-defined Parcelable objects during an Android AIDL RPC / IPC call In my previous post “Usi ...

  7. 在云服务器搭建WordPress博客(五)创建和管理文章分类

    不同主题的文章划分到不同的分类,有助于访客寻找他们想要的内容,提高用户体验.所以,为你的网站创建文章分类是很有必要的.那么,WordPress系统如何创建和管理文章分类呢?今天倡萌就简单介绍一下. 创 ...

  8. 1231: [Usaco2008 Nov]mixup2 混乱的奶牛 - BZOJ

    Description 混乱的奶牛 [Don Piele, 2007] Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S ...

  9. myeclipse一直bulid workspace 的解决

    解决方法转自: http://zhidao.baidu.com/link?url=gCj0XzorUUshtSFG2jXh6-Bxn28_LpcbTYasbgk9Qja_kw8Ex2kLzxFSYHN ...

  10. C#中Json和List/DataSet相互转换

    #region List<T> 转 Json        /// <summary>        /// List<T> 转 Json        /// & ...