DNA Consensus String UVA - 1368
题目链接:https://vjudge.net/problem/UVA-1368
题意:给出一组字符串,求出一组串,使与其他不同的点的和最小
题解:这个题就是一个点一个点求,利用桶排序,求出最多点数目的集合,如果点数相同,则按字母序最小的点为准
ac代码
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char ch[60][1100],ans[1100];
int main()
{
int n,x,y,j;
cin>>n;
while(n--)
{
int sum=0;
cin>>x>>y;
getchar();//吸收空行
for(int i=1; i<=x; i++)
scanf("%s",ch[i]);
for(j=0; j<y; j++)
{
int maxn=0;
int zi[30];
memset(zi,0,sizeof(zi));
for(int i=1; i<=x; i++)
zi[ch[i][j]-'A']++;
for(int i=0; i<26; i++)
if(zi[i]>maxn)
maxn=zi[i];
for(int i=0; i<26; i++)
if(zi[i]==maxn)
{
ans[j]=i+'A';
break;
}
}
ans[j]=0;
for(int i=1;i<=x;i++)
{
for(int j=0;j<y;j++)
if(ch[i][j]!=ans[j]) sum++;
}
cout<<ans<<endl;
cout<<sum<<endl;
}
return 0;
}
DNA Consensus String UVA - 1368的更多相关文章
- 贪心水题。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 ...
- 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 ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- uva 1368 DNA Consensus String
这道题挺简单的,刚开始理解错误,以为是从已有的字符串里面求最短的距离,后面才发现是求一个到所有字符串最小距离的字符串,因为这样的字符串可能有多个,所以最后取最小字典序的字符串. 我的思路就是求每一列每 ...
- 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题
https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...
- 【习题 3-7 UVA - 1368 】DNA Consensus String
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举每一位字母是什么. 从小到大枚举. 然后计算每一位的总贡献是多少. 取最小的那个输出. [代码] #include <bi ...
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- uvalive 3602 DNA Consensus String
https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...
随机推荐
- python实现简单的SVM
# -*- coding: utf-8 -*- from sklearn.svm import SVC import numpy as np print(X.shape,Y.shape) X = np ...
- Kubernetes 中 搭建 EFK 日志搜索中心
简介 Elastic 官方已经发布了Elasticsearch Operator ,简化了 elasticsearch 以及 kibana的部署与升级,结合 fluentd-kubernetes-da ...
- JavaScript基础Javascript中的循环(003)
1.普通循环JavaScript中一般的循环写法是这样的: // sub-optimal loop for (var i = 0; i < myarray.length; i++) { // d ...
- 集成Swagger在线调试
SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...
- Web开发HTTP协议知识_常用http方法、http状态码等(前端开发和面试必备))
http请求由三部分组成,分别是:请求行.消息报头.请求正文. HTTP(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议,常基于TCP的连接方式,HTTP1.1版本中给出一种持续连 ...
- angular入门--绑定字符串
要使用angularjs,首先得下载并且在页面中调用它 先上源码 <html ng-app="app1"> <head> <meta name=&qu ...
- Xor_Sum 题解
题目 You are given a positive integer \(N(1≦N≦10^{18})\). Find the number of the pairs of integers \(u ...
- NOI Online #3 提高组 T1水壶 题解
题目描述 有 n 个容量无穷大的水壶,它们从 1∼n 编号,初始时 i 号水壶中装有 Ai 单位的水. 你可以进行不超过 k 次操作,每次操作需要选择一个满足 1≤x≤n−1 的编号 x,然后把 x ...
- 虚拟机 - 桥接模式下,虚拟网卡没有 ip
背景 Linux 虚拟机,用桥接模式,敲 ifconfig命令,ens33 没有 ip 即没有红色圈住那部分 解决方案 修改配置文件 vim /etc/sysconfig/network-script ...
- 常用js代码片段(一)
1.如果数组所有元素都满足函数条件,则返回true.调用时,如果省略第二个参数,则默认传递布尔值. const all= (arr, fn=Boolean) => arr.every(fn); ...