【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;
}【58.33%】【codeforces 747B】Mammoth's Genome Decoding的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
		题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ... 
- 【23.33%】【codeforces 557B】Pasha and Tea
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【33.10%】【codeforces 604C】Alternative Thinking
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- 【25.33%】【codeforces 552D】Vanya and Triangles
		time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ... 
- 【33.33%】【codeforces 552B】Vanya and Books
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【33.33%】【codeforces 586D】Phillip and Trains
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【33.33%】【codeforces 608C】Chain Reaction
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- 【21.58%】【codeforces 746D】Green and Black Tea
		time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ... 
- 【codeforces 807D】Dynamic Problem Scoring
		[题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ... 
随机推荐
- 【插拔式】分页+bootstrap4(开源)
			1:分页源码 class Pagination(object): def __init__(self, PagerCount,Pages, perPageItemNum, maxPageNum): # ... 
- BZOJ2802Warehouse Store题解
			链接 我太菜了,连贪心题都不会写... 贪心思路很简单,我们能满足顾客就满足他,如果满足不了,就看之前的顾客中 有没有需求比该顾客多的顾客,如果有的话改为卖给这位顾客会使解更优 所以我们用一个优先队列 ... 
- Python中if __name__ == '__main__':理解
			在很多python脚本中在最后的部分会执行一个判断语句if __name__ == "__main__:",之后还可能会有一些执行语句.那添加这个判断的目的何在? 在python编 ... 
- @spoj - ADAMOLD@ Ada and Mold
			目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 N 的序列 A,将其划分成 K + 1 段,划分 ... 
- Linux下配置 Keepalived(心跳检测部署)
			首先呢,我想先给大家简单介绍一下什么是keepalived: Keepalived的作用是检测服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的服务器 ... 
- iOS 9适配系列教程:后台定位
			http://www.cocoachina.com/ios/20150624/12200.html Demo:GitHub地址 [iOS9在定位的问题上,有一个坏消息一个好消息]坏消息:如果不适配iO ... 
- POJ-3616_Milking Time
			Milking Time Time Limit: 1000MS Memory Limit: 65536K Description Bessie is such a hard-working cow. ... 
- Gym-101623H_High Score
			题意:t组数据,每组数据有abcd四个数,其中d可以加到abc任意一个数上(d可以拆分),求公式a^2 + b^2 + c^2 + 7 * min(a,b,c)的最大值. 题解:首先明确一点,平方的增 ... 
- Struts2整合Spring方法及原理
			一. Struts 2框架整合Spring步骤 1. 复制文件.复制struts2-spring-plugin-x-x-x.jar和spring.jar到WEB-INF/lib目录下.其中的x对应 ... 
- vlc 网页插件的 使用与控制 API
			下面开始使用教程: html文档结构: <object class="vlc" type='application/x-vlc-plugin' events='True' w ... 
