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. 如何在WCF中用TcpTrace工具查看发送和接收的SOAP消息

    WCF对消息加密(只对消息加密,不考虑Authorize)其实很简单,只要在server和client端的binding加入security mode为Message(还有Transport, Tra ...

  2. appium 获取android 粘贴板上的内容

    appium 新版本增加了获取粘贴板的内容.如果使用appium旧版本,获取粘贴板的内容不是那么容易的,甚至百度谷歌各种搜,都无法找到合适的解决方法.新版本获取android 粘贴板内容就显得很容易了 ...

  3. 使用ffmpeg 推流

    1.编译ffmpeg http://www.linuxidc.com/Linux/2014-11/109840.htm http://www.linuxidc.com/Linux/2013-02/78 ...

  4. 【Java虚拟机】浅谈Java虚拟机

    跨平台 Java的一大特性是跨平台,而Java是如何做到跨平台的呢? 主要依赖Java虚拟机,具体来说,是Java虚拟机在各平台上的实现. Java虚拟机在不同的平台有不同的实现.同一份字节码,通过运 ...

  5. 解决Redis之MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist o...

    解决Redis之MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist o... ...

  6. spring batch中用到的表

    1,批量表的前缀:{prefix}来自类AbstractJdbcBatchMetadataDao中的变量DEFAULT_TABLE_PREFIX 2,{prefix}job_execution:存放j ...

  7. 【iCore1S 双核心板_ARM】例程十三:SDIO实验——读取SD卡信息

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ HAL_SD_TransferStateTypedef State; /* USER CODE ...

  8. <时间的玫瑰>读书笔记

    投资不需要高等数学,只需要常识和智慧 一个人在市场里的输赢结果,实际上是对他人性优劣的奖惩 投资像孤独的乌龟与时间竞赛 时间是最有价值的资产,我们今天买入的股票不仅仅属于我们自己,它属于整个家族,我们 ...

  9. 模板, 保存&发布

    单击“视图”菜单中的“幻灯片模板”按钮,会弹出“幻灯片母版”选项卡,在此选项卡中,可以修改当前PPT的模板, 例如网上下载的幻灯片上的LOGO都可在这里去除. 模板设计总结 1. 背景可以选择纯色,也 ...

  10. Fedora Server 21下OpenJdk和Oracle Jdk共存

    最新文章:Virson's Blog 参考文章:博客园-三维蚂蚁 Linux公社 1.首先需要下载对应平台的Jdk:Oracle 官网 2.使用yum或rpm命令安装Jdk: yum install ...