20200314(ABC)

传送门

A - Display Size CodeForces - 747A

这道题思路很清晰,就是求因子的差最小

#include<bits/stdc++.h>
using namespace std;
int n,x,y,m=0x3f3f3f3f;
int main(){
	scanf("%d",&n);
	for(int i=1;i*i<=n;i++){
		if(n%i!=0)
		continue;
		if(m>abs(i-n/i)){
			x=i;
			y=n/i;
		}
	}
	printf("%d %d\n",x,y);
}

B - Mammoth’s Genome Decoding CodeForces - 747B

B题意:一串字符串,可以把’?‘用’A’,‘C’,‘G’,‘T’进行替换。使最后字符串中A C G T的数目相同。
题解:先判一下是否能对4取整,不能取整的话直接输出。否则,用数组统计A C G T的数量,如果数组小于n/4的话就不断将字符串中的’?'提换成相应的字符。最后一个循环查看数组中是否都等于n/4。

#include<bits/stdc++.h>
using namespace std;
string s;
int n,m;
map<char,int> p;
int main(){
	cin>>n;
	cin>>s;
	if(n%4!=0){
		cout<<"==="<<endl;
		return 0;
	}
	m=n/4;
	p['A']=0;p['G']=0;p['C']=0;p['T']=0;
	for(int i=0;i<s.length();i++){
		p[s[i]]++;
		if(s[i]!='?'&&p[s[i]]>m){
			cout<<"==="<<endl;
			return 0;
		}
	}
	for(int i=0;i<s.length();i++){
		if(s[i]=='?'){
			for(map<char,int>::iterator it=p.begin();it!=p.end();it++){
				if(it->first!='?'&&it->second<m){
					char c=it->first;
					p[c]++;
					s[i]=c;
					break;
				}
			}
		}
	}
	cout<<s<<endl;
}
发布了115 篇原创文章 · 获赞 3 · 访问量 1760

猜你喜欢

转载自blog.csdn.net/qq_43721152/article/details/104887987
ABC
今日推荐