zoukankan      html  css  js  c++  java
  • 问题 I: Ponk Warshall

    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; 
    } 
  • 相关阅读:
    【BZOJ-4031】小z的房间 Matrix-Tree定理 + 高斯消元解行列式
    无题
    【BZOJ-4261】建设游乐场 最大费用最大流
    【BZOJ-2888】资源运输 LCT + 启发式合并
    【Codeforces666E】Forensic Examination 后缀自动机 + 线段树合并
    【BZOJ-2142】礼物 拓展Lucas定理
    【BZOJ-3672】购票 树分治 + 斜率优化DP
    【BZOJ-3218】a+b Problem 最小割 + 可持久化线段树
    【BZOJ-1913】signaling信号覆盖 极角排序 + 组合
    【BZOJ-4408】神秘数 可持久化线段树
  • 原文地址:https://www.cnblogs.com/lipu123/p/14728100.html
Copyright © 2011-2022 走看看