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. C# 整形数组排序

    static void Main(string[] args) { , , , , , , , , , }; Array.Sort(numbers); Array.ForEach<int> ...

  2. nodejs ssh2

    https://www.npmjs.com/package/ssh2 npm install ssh2  ssh2文件下载: //前台命令下发 app.get('/test/fileDownload' ...

  3. php学习日志(5)-解决Windows Live Writer错误:WindowsLive.Writer.CoreServices.HttpRequestHelper的类型初始值设定发生异常

    以前用Windows Live Writer写日志都好好的,前几天用写完日志,点击发布,突然弹出意外错误:“WindowsLive.Writer.CoreServices.HttpRequestHel ...

  4. js文本框验证

    1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...

  5. CentOS 6.4 安装搭建 Scrapy 0.22 环境

    一.安装Python2.7.6 更新CentOS lib库文件 yum -y update 安装开发工具包 yum groupinstall -y development 安装扩展包 yum inst ...

  6. Python标准库之urllib,urllib2自定义Opener

    urllib2.urlopen()函数不支持验证.cookie或者其它HTTP高级功能.要支持这些功能,必须使用build_opener()函数创建自定义Opener对象. 1. build_open ...

  7. Python LOGGING使用方法

    Python LOGGING使用方法 1. 简介 使用场景 场景 适合使用的方法 在终端输出程序或脚本的使用方法 print 报告一个事件的发生(例如状态的修改) logging.info()或log ...

  8. 1095. Cars on Campus (30)

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

  9. C语言的sizeof

    今天帮同学想用C实现数组的折半查找,本来算法挺简单的,可是折腾了好几个小时才发现问题在哪,这个sizeof坑人不浅啊. #include<stdio.h> void m(int []); ...

  10. 关于使用视图进行分页时出现当前记录集不支持书签的错误解决方法及原因(asp)

    一般在使用视图进行查询时,视图中意般都关联了两个或者更多个表,一般在这种情况下才会使用视图,但是但我在使用视图来查询数据时没有问题,但是一旦在分页中使用到视图进行查询就会出现错误提示如下: ADODB ...