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
*/

【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题的更多相关文章

  1. uva 1368 DNA Consensus String

    这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...

  2. UVa 3602 - DNA Consensus String 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. 贪心水题。UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

    UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { ; ){ ; ) r ...

  4. 紫书第三章训练1 E - DNA Consensus String

    DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...

  5. uva1368 DNA Consensus String

    <tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...

  6. DNA Consensus String

    题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...

  7. 【习题 3-7 UVA - 1368 】DNA Consensus String

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bi ...

  8. DNA Consensus String UVA - 1368

    题目链接:https://vjudge.net/problem/UVA-1368 题意:给出一组字符串,求出一组串,使与其他不同的点的和最小 题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目 ...

  9. uvalive 3602 DNA Consensus String

    https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...

随机推荐

  1. Java socket保存示例(不使用base64)解决中文乱码问题

    MultiThreadServer.java package com.my.nubase64; import java.io.BufferedReader; import java.io.Buffer ...

  2. linux下zip包处理

    先来看例子: zip命令可以用来将文件压缩成为常用的zip格式.unzip命令则用来解压缩zip文件. 1. 我想把一个文件abc.txt和一个目录dir1压缩成为yasuo.zip: # zip - ...

  3. Android 实现顶层窗口、浮动窗口(附Demo)

    做过Window程序开发的朋友应该都知道,我们要把程序窗口置顶很简单,只要设置一些窗口属性即可.但是到了Android,你无法简单设置一个属性,就让Android的Activity置顶.因为只要有新的 ...

  4. JVM——Java HotSpot VM Options

    JVM常用参数 参数名称 含义 默认值  描述 -Xms 初始堆大小 物理内存的1/64(<1GB) 默认(MinHeapFreeRatio参数可以调整)空余堆内存小于40%时,JVM就会增大堆 ...

  5. Centos 6.4 安装erlang&rabbitmq

    1. 安装 erlang 1.1 准备工作,先安装依赖库 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-d ...

  6. Linux下MySQL5.7.18二进制包安装(无默认配置文件my_default.cnf)

    最新在学习MySQL,纯新手,对Linux了解的也不多,因为是下载的最新版的MySQL(MySQL5.7.18)二进制包,CentOS7.2下测试安装,方便以后折腾.大概步骤如下,安装删除反复折腾了几 ...

  7. 为何谷歌围棋AI AlphaGo可能会把李世石击溃

    /* 版权声明:可以随意转载,转载时请标明文章原始出处和作者信息 .*/ author: 张俊林 谷歌DeepMind开发的人工智能围棋程序AlphaGo以5:0的压倒性优势击败了欧洲围棋冠军.专业二 ...

  8. java.security.ProviderException: java.security.KeyException

    本机部署没问题,部署到linux服务器报错: javax.net.ssl.SSLException: java.security.ProviderException: java.security.Ke ...

  9. Ubuntu Linux 解决 bash ./ 没有那个文件或目录 的方法

    Ubuntu Linux 解决 bash ./ 没有那个文件或目录 的方法 经常在ubuntu 64位下运行 ./xxx 会跳出来说没有这个文件或者目录,但是ls看又有这个文件,很是奇怪. 其实原因很 ...

  10. [转]Git忽略规则及.gitignore规则不生效的解决办法

    在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如无,则需自己手工建立此文件).这个文件每一行保存了一个匹配的规则例如: # 此为注 ...