UVa 1368 - DNA Consensus String
生活随笔
收集整理的這篇文章主要介紹了
UVa 1368 - DNA Consensus String
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這是連續第8次1Y了,哈哈哈,不過,不過這題看起來挺嚇人,讀完才知道就是讓球一個目標DNA序列,和每個所給序列最相近。不是從里面選,第一次就是這么理解的然后。。。。。是自己用A C G T中組合。如果有多解選字典序最小的。
題目定位 : 字符串水題。 貌似有點貪心的意思。
上Java代碼 :
import java.util.*;public class Main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);int t = scan.nextInt();while(t-- > 0) {int m = scan.nextInt();int n = scan.nextInt();StringBuilder sb = new StringBuilder();String s;DNA[] dna = new DNA[m + 1];for(int i=0; i<m; i++) {s = scan.next();dna[i] = new DNA(s, 0);}int[] cnt = new int[4];int dis = 0;for(int j=0; j<n; j++) {Arrays.fill(cnt, 0);for(int i=0; i<m; i++) {if(dna[i].str.charAt(j) == 'A') {cnt[0] ++;}if(dna[i].str.charAt(j) == 'C') {cnt[1] ++;}if(dna[i].str.charAt(j) == 'G') {cnt[2] ++;}if(dna[i].str.charAt(j) == 'T') {cnt[3] ++;}}int max = cnt[0];char ch = 'A';for(int k=1; k<4; k++) {if(cnt[k] > max) {max = cnt[k];if(k == 1) {ch = 'C';}if(k == 2) {ch = 'G';}if(k == 3) {ch = 'T';}}}if(ch == 'A') {dis += cnt[1] + cnt[2] + cnt[3];}if(ch == 'C') {dis += cnt[0] + cnt[2] + cnt[3];}if(ch == 'G') {dis += cnt[0] + cnt[1] + cnt[3];}if(ch == 'T') {dis += cnt[1] + cnt[2] + cnt[0];}sb.append(ch);}System.out.println(sb);System.out.println(dis);}}} class DNA {public String str;public int cnt;public DNA(String str, int cnt) {this.str = new String(str);this.cnt = cnt;} }
?
?
轉載于:https://www.cnblogs.com/wxisme/p/4363741.html
總結
以上是生活随笔為你收集整理的UVa 1368 - DNA Consensus String的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Reporting Service 20
- 下一篇: SQL Server 审核(Audit)