【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题
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 字符串+贪心+阅读题的更多相关文章
- uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 贪心水题。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 ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- uva1368 DNA Consensus String
<tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...
- DNA Consensus String
题目(中英对照): DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It co ...
- 【习题 3-7 UVA - 1368 】DNA Consensus String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bi ...
- DNA Consensus String UVA - 1368
题目链接:https://vjudge.net/problem/UVA-1368 题意:给出一组字符串,求出一组串,使与其他不同的点的和最小 题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目 ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
随机推荐
- [AaronYang]那天有个小孩跟我说Js正则
按照自己的思路学习Node.Js 随心出发.突破正则冷门知识点,巧妙复习正则常用知识点 标签:AaronYang 茗洋 Node.Js 正则 Javascript 本篇博客地址:http://ww ...
- 目标检测比赛---Google AI Open Images - Object Detection Track
https://www.kaggle.com/c/google-ai-open-images-object-detection-track#Evaluation Submissions are eva ...
- Java 8 – MinguoDate examples
1. LocalDate -> MinguoDate Review a full example to convert a LocalDate to MinguoDate TestMinguoD ...
- 小型IT部门建设之我见
关于IT团队建设,一般的原则是四大块组成: 1:业务分析师,对接业务部门,把业务需求转变成技术需求 专注于BRS( Business Requirement Speci ...
- 物联网架构成长之路(11)-Redis缓存主从复制
1. 说明 在我的物联网平台框架框架中,会用到Redis这个中间件.作为EMQ权限认证的缓存.https://www.cnblogs.com/think-in-java/p/5123884.html ...
- 【Tomcat】Tomcat 系统架构与设计模式,第 2 部分: 设计模式分析
这个分为两个部分的系列文章研究了 Apache Tomcat 服务器的系统架构以及其运用的很多经典设计模式.第 1 部分 分析了 Tomcat 的工作原理,第 2 部分将分析 Tomcat 中运用的许 ...
- 【emWin】例程十三:字库放到外部存储器
介绍: 本例将字库文件放到SD卡中,通过读取SD卡中的字库文件在液晶上显示文字. 实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1bo0yTLd 密码:i4sm ...
- 【LINUX】——如何配置宿主机和虚拟机IP在同一网段
宿主机:win7 10.8.2.50 255.255.255.0 虚拟机:redhat 如果使用 NAT 的网络连接方式,虚拟机的 IP 会被分配为 192.168.*.* 网段,从虚拟机 ping ...
- Caltech数据使用详情
Caltech官网: http://www.vision.caltech.edu/Image_Datasets/CaltechPedestrians/ 以Caltech测试集为例(大概是4095个图片 ...
- Java如何获取本地计算机的IP地址和主机名?
在Java编程中,如何获取本地计算机的IP地址和主机名? 以下示例显示如何使用InetAddress类的getLocalAddress()方法获取系统的本地IP地址和主机名. package com. ...