*[hackerrank]ACM ICPC Team
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的更多相关文章
- ACM ICPC Team
Link: https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807 def count_max_to ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 890A - ACM ICPC 暴力
A. ACM ICPCtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputst ...
- 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 ...
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛
比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...
- ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))
祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
随机推荐
- JavaScript 同源策略
在JavaScript安全性限制Same-Origin Policy(同源策略)=>JavaScript只能访问与包含它的文档在同一域下的内容. 同源=>域名+协议+端口相同.
- php生成txt文件换行问题
用双引号即"\r\n"换行,不能用单引号即'\r\n'.
- 图片放大缩小(和ViewPager配合使用流畅显示)--第三方开源--PhotoView
图片的放大缩小实现效果是使用的github上的一个开源项目photoView实现的,下载地址:https://github.com/chrisbanes/PhotoView 下面看测试代码: acti ...
- python:执行一个命令行N次
经常希望可以执行一个命令行N次...windows下没有现成的工具(有?推荐给我!) 用python写一个... #!/usr/bin/evn python #coding: utf-8 " ...
- ASP.NET MVC 技术债务
ASP.NET MVC 缓存.本地化和监控诊断 ASP.NET MVC 认证与授权 Entity Framework 创建数据模型
- CSS3实战之新增的选择器
用的比较少 看到知道怎么回事就ok http://www.w3.org/TR/css3-selectors/#selectors http://www.cnblogs.com/jscode/archi ...
- Daject初探 - 一个开源关系型数据库对象关系映射(ORM)模型
Daject简介 Daject是用php写的一个关系型数据库抽象模型,通过该模型,可以在不写任何SQL或写很少的SQL就能执行大多数数据库查询操作.Daject具有面向对象,跨数据库的优点,通过数据库 ...
- windows环境下MySQL重启的命令行说明
ctrl+r 弹出运行框,输入cmd,然后再控制太输入命令: 1.点击“开始”->“运行”(快捷键Win+R). 2.停止:输入 net stop mysql 3.启动:输入 net start ...
- java collections
http://www.docjar.com/docs/api/java/util/technotes/guides/collections/changes4.html http://www.docja ...
- LintCode-Search 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of ...