zoukankan      html  css  js  c++  java
  • 【58.33%】【codeforces 747B】Mammoth's Genome Decoding

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    The process of mammoth’s genome decoding in Berland comes to its end!

    One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: ‘A’, ‘C’, ‘G’ or ‘T’. Unrecognized nucleotides are coded by a question mark ‘?’. Thus, s is a string consisting of letters ‘A’, ‘C’, ‘G’, ‘T’ and characters ‘?’.

    It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.

    Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.

    Input
    The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome.

    The second line contains the string s of length n — the coded genome. It consists of characters ‘A’, ‘C’, ‘G’, ‘T’ and ‘?’.

    Output
    If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: “===” (without quotes).

    Examples
    input
    8
    AG?C??CT
    output
    AGACGTCT
    input
    4
    AGCT
    output
    AGCT
    input
    6
    ????G?

    output

    input
    4
    AA??

    output

    Note
    In the first example you can replace the first question mark with the letter ‘A’, the second question mark with the letter ‘G’, the third question mark with the letter ‘T’, then each nucleotide in the genome would be presented twice.

    In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.

    In the third and the fourth examples it is impossible to decode the genom.

    【题目链接】:http://codeforces.com/contest/747/problem/B

    【题解】

    最后每种碱基肯定都是n/4;
    当然如果一开始就大于n/4要输出无解.
    如果n不能被4整除;也直接输出无解。
    然后枚举每一个问号要换成什么碱基就好;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const char temp[5] = {'0','A','T','C','G'};
    const double pi = acos(-1.0);
    
    int n,q =0,a[5];
    string s;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        cin >> n;
        cin >> s;
        rep1(i,0,n-1)
            if (s[i]=='?')
                q++;
            else
                if (s[i] == 'A')
                    a[1]++;
                else
                    if (s[i] == 'T')
                        a[2]++;
                    else
                        if (s[i] == 'C')
                            a[3] ++;
                        else
                            if (s[i] =='G')
                                a[4]++;
        if ((n%4)!=0)
        {
            puts("===");
            return 0;
        }
        n/=4;
        rep1(i,1,4)
            if (a[i]>n)
            {
                puts("===");
                return 0;
            }
        int len = s.size();
        rep1(i,0,len-1)
            if (s[i]=='?')
            {
                bool fi = false;
                rep1(j,1,4)
                    if (a[j]<n)
                    {
                        a[j]++;
                        s[i] = temp[j];
                        fi = true;
                        break;
                    }
                if (!fi)
                {
                    puts("===");
                    return 0;
                }
                q--;
            }
        cout << s<<endl;
        return 0;
    }
  • 相关阅读:
    创龙TMS320C6748开发板串口和中断学习笔记
    RTL8195AM开发板使用
    CC3100BoosterPack和CC31XXEMUBOOST板子的测试
    利尔达NB-IOT的PSM和eDRX低功耗模式笔记
    【原创】大数据基础之Zookeeper(3)选举算法
    【原创】大数据基础之Zookeeper(2)源代码解析
    【原创】大数据基础之Zookeeper(1)介绍、安装及使用
    【原创】论码农的财富修养
    【原创】大叔案例分享(2)处理大批量数据时如何实现“高效”同时实现“断点续传”功能
    【原创】大数据基础之Spark(1)Spark Submit即Spark任务提交过程
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626796.html
Copyright © 2011-2022 走看看