https://cn.vjudge.net/problem/UVA-1368

二维的hamming距离算法:

For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b.

int hamming_distance(unsigned x, unsigned y)
{
int dist = ;
unsigned val = x ^ y; // Count the number of bits set
while (val != )
{
// A bit is set, so increment the count and clear the bit
dist++;
val &= val - ;
} // Return the number of differing bits
return dist;
}

Two example distances: 100→011has distance 3; 010→111 has distance 2

以上是题外话,

其实二进制hamming距离和这题无关啦,就是一个暴力算hamming距离,然后贪心地找

坑点:for(i,0,len)写错,应该是len-1,很难debug出来

orz 我先用set,然后发现还是要重载运算符orz 最后map暴力,还不如数组呢

#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
#define pb push_back
#define mp make_pair
#define x first
#define y second
const int maxn = ;
ll n,m; string s[maxn];
map<char, int> mmp; int main()
{ int t; cin >> t;
while (t--) {
cin >> n >> m;
rep(i, , n)cin >> s[i];
string ans ; ans.clear();
int now = , mn = ;
rep(j, , m-) { mmp.clear();
rep(i, , n) {
//cnt[s[i][j]]++;
mmp[s[i][j]]++; }
pair<char, int> temp = { 'Z',- };
for (auto t : mmp)if (t.second > temp.second|| (t.second == temp.second&&t.first<temp.first))temp = t;
ans.push_back(temp.first);
mn += n -temp.second; }
cout << ans << endl;
cout << mn << endl;
} cin >> n;
return ;
}
/*
3
5 8
TATGATAC
TAAGCTAC
AAAGATCC
TGAGATAC
TAAGATGT
4 10
ACGTACGTAC
CCGTACGTAG
GCGTACGTAT
TCGTACGTAA
6 10
ATGTTACCAT
AAGTTACGAT
AACAAAGCAA
AAGTTACCTT
AAGTTACCAA
TACTTACCAA
*/

最新文章

  1. Dynamics XRM Tools 2015 2016
  2. docker私有库UI和添加私有库到本机能够push和pull
  3. [高斯消元] POJ 2345 Central heating
  4. 集成 Union Pay - 银联支付
  5. 一道面试题:按照其描述要求用java语言实现快速排序
  6. nginx+tomcat集群配置(1)---根目录设定和多后端分发配置
  7. C内联汇编
  8. js实现placeholder效果
  9. iOS和hybird移动端性能
  10. Search a 2D Matrix ——LeetCode
  11. panel控件 换行
  12. mysql登录报错 ERROR 1045 (28000)
  13. 5_jQuery选择器
  14. Java boolean类型
  15. java工程师学习线路图
  16. 浏览器通过file://访问文件和通过http://访问文件有什么区别
  17. Caused by: java.lang.ClassNotFoundException: com.mchange.v2.ser.Indirector
  18. 【一天一道LeetCode】#101. Symmetric Tree
  19. Jetson tk1 刷机教程
  20. node.js中ws模块创建服务端和客户端,网页WebSocket客户端

热门文章

  1. WCF中记录SOAP消息日志
  2. sql server 2008 express 安装的时提示“重启计算机失败&quot;
  3. 高性能IO之Reactor模式(转载)
  4. 引导修复软件boot-repair
  5. Spatial Sound Research
  6. java框架篇---hibernate入门
  7. bootstrap 3.0 LESS源代码浅析(一)
  8. Spring Security 认证流程
  9. Go_14:GoLang中 json、map、struct 之间的相互转化
  10. Login failed for user &#39;IIS APPPOOL\ASP.NET v4.0&#39;