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. Rocket Typist for Mac(增强型文本快速输入工具)破解版安装

    1.软件简介    Rocket Typist 是 macOS 系统上一款增强型文本快速输入工具,我们可以利用这款工具预先设置保存好很多日常生活学习或是工作中常用的文本片段,还能设定部分内容为变量,当 ...

  2. Gitbook 命令行工具

    1.Gitbook 简介 1.1 Gitbook GitBook 是一个基于 Node.js 开发的命令行工具,使用它可以很方便的管理电子书,GitBook 是目前最流行的开源书籍写作方案. 使用 G ...

  3. 反射简化switch语句

    1. 一个简单工厂类 public class FactoryModule { public ModuleIntf getModule(String moduleType) { ModuleIntf ...

  4. 分享一个Godaddy的优惠码,可以优惠35%——2013-11-23

    国外的域名注册商就是好,还有优惠码,付费的时候贴上优惠码就能免相应的金额,不错. 在网上找的一个35%优惠的优惠码,可以买域名和主机.(主机就免了,有点贵,域名不错) 我买了个com域名,原本$12. ...

  5. DataTables 全局设置中文语言

    参考来源:https://blog.csdn.net/qq_22690445/article/details/79682311 $.fn.dataTable.defaults.oLanguage = ...

  6. 第三部分:Android 应用程序接口指南---第二节:UI---第六章 对话框

    第6章 对话框 一个对话框是一个小窗口,提示用户做出决定或输入额外的信息,一个对话框不填充屏幕并且通常用于在程序运行时中断,然后弹出通知提示用户,从而直接影响到正在运行的程序.图6-1就是对话框的外观 ...

  7. 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试

    <软件测试自动化之道>读书笔记 之 SQL 存储过程测试 2014-09-28 待测程序测试程序   创建测试用例以及测试结果存储  执行T-SQL脚本  使用BCP工具导入测试用例数据  ...

  8. Python测试DB2连通性

    Python测试数据库连通性: #!/usr/bin/python27 #encoding: utf-8 import ibm_db import os import sys def find_db( ...

  9. 基音检测算法的性能:Performance Evaluation of Pitch Detection Algorithms

    http://access.feld.cvut.cz/view.php?cisloclanku=2009060001 Vydáno dne 02. 06. 2009 (15123 přečtení) ...

  10. C语言 · 2n皇后问题

    基础练习 2n皇后问题   时间限制:1.0s   内存限制:512.0MB        锦囊1 搜索算法. 锦囊2 先搜索n皇后的解,在拼凑成2n皇后的解. 问题描述 给定一个n*n的棋盘,棋盘中 ...