ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

问题 I: Ponk Warshall

2021-05-03 20:36:33  阅读:196  来源: 互联网

标签:include Warshall nucleobases two 问题 int Ponk rock gene


Listening to the rock music permutes your nuclear DNA. This astonishing and unbelievable fact was recently published in the Rock Nature Weekly, one of the top scientific journals on the planet. Part of the research was to take DNA samples from volunteers, both before and after the rock concerts season. The samples were processed and various genes isolated from the samples. For each person, each gene was isolated twice: The variant before the rock season and the variant after the season. These two variants were paired and in many cases one variant was found to be some permutation of the other variant in the pair.
The next step in the research is to determine how the permutations happen. The prevalent hypothesis suggests that a permutation is composed of a sequence of transpositions, so-called swaps. A swap is an event (its chemistry is not fully understood yet) in which exactly two nucleobases in the gene exchange their places in the gene. No other nucleobases in the gene are affected by the swap. The positions of the two swapped nucleobases might be completely arbitrary.
To predict and observe the movement of the molecules in the permutation process, the researchers need to know the theoretical minimum number of swaps which can produce a particular permutation of nucleobases in a gene. We remind you that the nuclear DNA gene is a sequence of nucleobases cytosine, guanine, adenine, and thymine, which are coded as C, G, A, and T, respectively.

输入

The input contains two text lines. Each line contains a string of N capital letters “A”, “C”, “G”,or “T”, (1 ≤ N ≤ 106 ). The two strings represent one pair of a particular gene versions. The first line represents the gene before the rock season, the second line represents the same gene from the same person after the rock season. The number of occurrences of each nucleobase is the same in both strings.

输出

Output the minimum number of swaps that transform the first gene version into the second one.

样例输入 Copy

CGATA
ATAGC

样例输出 Copy

2
这个题就是问你从上面的串变成下面的串,最少操作几次(调换两个)
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<map> 
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
char a[maxn],b[maxn];
int c[1000][1000];
map<char,int>mp;
int main(){
    mp['A']=0;
    mp['T']=1;
    mp['C']=2;
    mp['G']=3;
    scanf("%s",a);
    scanf("%s",b);
    int len=strlen(a);
    for(int i=0;i<len;i++){
        if(a[i]!=b[i]) 
            c[mp[a[i]]][mp[b[i]]]++;    
    }
    int ans=0;
    for(int i=0;i<=3;i++){
        for(int j=i;j<=3;j++){
            int t=min(c[i][j],c[j][i]);
            c[i][j]-=t;
            c[j][i]-=t;
            ans+=t;
        }
    }
    for(int i=0;i<=3;i++){
        for(int j=0;j<=3;j++){
            for(int k=0;k<=3;k++){
                int z=min(c[i][j],min(c[j][k],c[k][i]));
                c[i][j]-=z;
                c[j][k]-=z;
                c[k][i]-=z;
                ans+=2*z;
            }
        }
    }
    for(int i=0;i<=3;i++){
        for(int j=0;j<=3;j++){
            for(int k=0;k<=3;k++){
                for(int z=0;z<=3;z++){
                    int p=min(c[i][j],min(c[j][z],min(c[z][k],c[k][i])));
                    c[i][j]-=p;
                    c[j][z]-=p;
                    c[z][k]-=p;
                    c[k][i]-=p;
                    ans+=3*p;
                }
            }
        } 
    }
    cout<<ans<<endl; 
} 

 

标签:include,Warshall,nucleobases,two,问题,int,Ponk,rock,gene
来源: https://www.cnblogs.com/lipu123/p/14728100.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有