*[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神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
随机推荐
- Stanford parser学习:LexicalizedParser类分析
上次(http://www.cnblogs.com/stGeekpower/p/3457746.html)主要是对应于javadoc写了下LexicalizedParser类main函数的功能,这次看 ...
- jQuery select的操作代码
jQuery對select的操作的实际应用代码. //改變時的事件 复制代码代码如下: $("#testSelect").change(function(){ //事件發生 j ...
- phpExcel导出excel的类,每步都有说明
require_once WEB_PATH . '/lib/PHPExcel/PHPExcel.php'; require_once WEB_PATH . '/lib/PHPExcel/PHPExce ...
- 给view 添加事件
//绑定图片点击事件 UITapGestureRecognizer *g=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@select ...
- require.js入门指南(三)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- Android屏幕像素密度适配详解
讲到像素密度,我们先要搞明白什么是像素密度,像素密度的字面上的意思为手机屏幕上一定尺寸区域内像素的个数.在Android开发中, 我们一般会使用每英寸像素密度(dpi)这样一个单位来表示手机屏幕的像素 ...
- C语言的sizeof
今天帮同学想用C实现数组的折半查找,本来算法挺简单的,可是折腾了好几个小时才发现问题在哪,这个sizeof坑人不浅啊. #include<stdio.h> void m(int []); ...
- CentOS 7.0安装MPlayer
自带的播放器不管rmvb还是mp4都不能播放,也搜索不到解码器. CentOS7epel装不上所以也没有rpmfusion,所以决定自己编译mplayer 首先是要获取源代码. 首先是主程序的源代码. ...
- 基于UUID生成短ID
为什么需要短ID 数据库操作过程最常用到: 自增ID UUID 前者多数依赖Mysql的auto_increment,但数据移植麻烦. 如果是主从或主主,不同库里自增ID还可能不一致. 后者长度是个问 ...
- 【quartz】 理论知识
属性的介绍 1.调度器属性:分别设置调度器的实例名(instanceName) 和实例 ID (instanceId).属性 org.quartz.scheduler.instanceName 可以是 ...