codeforces-747

本文介绍了解决两个具体算法问题的方法:一是确定像素数量为n的矩形显示屏的最佳尺寸;二是对含有未知核苷酸的猛犸象基因组进行解码,使其各类核苷酸数量相等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:点击打开链接

A. Display Size
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels.

Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixelsb, so that:

  • there are exactly n pixels on the display;
  • the number of rows does not exceed the number of columns, it means a ≤ b;
  • the difference b - a is as small as possible.
Input

The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.

Output

Print two integers — the number of rows and columns on the display.

Examples
input
8
output
2 4
input
64
output
8 8
input
5
output
1 5
input
999999
output
999 1001
Note

In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.

In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.

In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.


#include<cstdio>
#include<cmath>
using namespace std;
int n;
int main()
{
	while(~scanf("%d",&n))
	{
		int mid=sqrt(n*1.0);
		int ans;
		for(int i=mid;i>=1;i--)
		{
			if(n%i==0)
			{
				ans=i;
				break;
			}
		}
		printf("%d %d\n",ans,n/ans);
	}
	return 0;
}

题目链接: 点击打开链接

B. Mammoth's Genome Decoding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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.


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char str[260];
int num[4];
char ch[]={'A','C','G','T'};
int main()
{
	while(~scanf("%d",&n))
	{
		scanf("%s",str);
		if(n%4)
		{
			puts("===");
			continue;
		}
		memset(num,0,sizeof(num));
		for(int i=0;i<n;i++)
		{
			if(str[i]=='A')
				num[0]++;
			if(str[i]=='C')
				num[1]++;
			if(str[i]=='G')
				num[2]++;
			if(str[i]=='T')
				num[3]++;
		}
		int cnt=n/4;
		if(num[0]>cnt||num[1]>cnt||num[2]>cnt||num[3]>cnt)
		{
			puts("===");
			continue;
		}
		for(int i=0;i<n;i++)
		{
			if(str[i]=='?')
			{
				int k;
				for(int j=0;j<4;j++)
				{
					if(num[j]<cnt)
					{
						k=j;
						num[j]++;
						break;
					}
				}
				str[i]=ch[k];
			}
		}
		puts(str);
	}
	return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值