A - Two Abbreviations

本文探讨了一个复杂的字符串匹配问题,旨在判断是否存在满足特定条件的好字符串,并找出其最短长度。条件包括字符串长度的整除性及通过特定方式组合字符得到目标字符串。文章提供了算法思路和代码实现,涉及数学、算法设计与字符串操作。

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

You are given a string SS of length NN and another string TT of length MM. These strings consist of lowercase English letters.

A string XX is called a good string when the following conditions are all met:

  • Let LL be the length of XX. LL is divisible by both NN and MM.
  • Concatenating the 11-st, (LN+1)(LN+1)-th, (2×LN+1)(2×LN+1)-th, ......, ((N−1)×LN+1)((N−1)×LN+1)-th characters of XX, without changing the order, results in SS.
  • Concatenating the 11-st, (LM+1)(LM+1)-th, (2×LM+1)(2×LM+1)-th, ......, ((M−1)×LM+1)((M−1)×LM+1)-th characters of XX, without changing the order, results in TT.

Determine if there exists a good string. If it exists, find the length of the shortest such string.

Constraints

  • 1≤N,M≤1051≤N,M≤105
  • SS and TT consist of lowercase English letters.
  • |S|=N|S|=N
  • |T|=M|T|=M

Input

Input is given from Standard Input in the following format:

NN MM
SS
TT

Output

If a good string does not exist, print -1; if it exists, print the length of the shortest such string.


Sample Input 1 Copy

Copy

3 2
acp
ae

Sample Output 1 Copy

Copy

6

For example, the string accept is a good string. There is no good string shorter than this, so the answer is 66.


Sample Input 2 Copy

Copy

6 3
abcdef
abc

Sample Output 2 Copy

Copy

-1

Sample Input 3 Copy

Copy

15 9
dnsusrayukuaiia
dujrunuma

Sample Output 3 Copy

Copy

45

重要的坑说三遍 

long long

long long

long long
以后没啥事直接用long long

#include<bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b)
{
	 return (!b)?a:gcd(b,a%b);
}
int main()
{
	long long n,m;
	 map<long long ,long long>q;
	 cin>>n>>m;
	 int flag=0;
	 string s,t;
	 cin>>s;
	 cin>>t;
	/* if(n==n*m/gcd(n,m)||m==n*m/gcd(n,m))
	 cout<<"-1"<<endl;
	 else
	 cout<<n*m/gcd(n,m)<<endl;*/
	 long long l=n*m/gcd(n,m);
	 for(long long i=0;i<n;i++)
	 {
	 	 
	 	 	q[i*l/n+1]=s[i]-'a'+1;
		  
	 	 
	 }
	// cout<<endl;
	 
	 for(long long i=0;i<m;i++)
	 {
	 //	 cout<<i*l/m+1<<endl;
	 	 
	 	 	if(q[i*l/m+1]==t[i]-'a'+1||q[i*l/m+1]==0)
	 	 	continue;
	 	 	else
	 	 	{
	 	 		flag=1;
	 	 		break;
			  }
		  
	 }
	 if(flag)printf("-1");
	 else printf("%lld",l);
 } 

 

Step 1: Prepare the bed file and pep file of the species Firstly, please prepare bed files for all species and fasta format files for proteins. Determine a four character abbreviation for each species, for example, Arabidopsis thaliana can be set as , and Amborella trichopoda can be set as . The bed file contains the location information of cDNA, and the format requirements are as follows: the first column is the chromosome number, which needs to be preceded by the species abbreviation and the first two characters must be unique to the species (distinguished by uppercase and lowercase lettersath_atr_) bed file of Arabidopsis thaliana: aThChr1 ath_AT1G01010 3631 5899 bed file of Amborella trichopoda: Atrscaffold00001 atr_scaffold00001.1atr 3379 6049 The second column is the ID number of cDNA, which needs to include the species abbreviation, such as ath_T1G01010. The third column represents the starting position of cDNA, and the fourth column represents the ending position of cDNA. For the fasta file of proteins, please ensure that the protein ID in the file corresponds to the ID in the bed file, and change the file suffix to. pep. Ensure that the bed file and pep file with the same abbreviation, for example, the bed and pep files corresponding to Arabidopsis thaliana are ath.bed and ath.pep, respectively. Step 2: Create a name list file that includes species abbreviations and taxonomic information Fill in the names of the pep file and bed file corresponding to the species in the first column of the name list, the abbreviation of the ID in the second column of the name list, and the classification information of the species in the third, fourth, fifth, and sixth columns. for example: #file_name ID_abbreviation Clade Order Family Species_Name Mdgd Mdgd Super-Rosides Rosales Rosaceae Malus x domestica ppe ppe_ Super-Rosides Rosales Rosaceae Prunus persica ath ath_ Super-Rosides Brassicales Brassicaceae Arabidopsis thaliana Alyr Alyr Super-Rosides Brassicales Brassicaceae Arabidopsis lyrata atr atr_ Basal-Angiosperm Amborellales Amborellaceae Amborella trichopoda Step 3: Constructing a species overall collinear network Run the synetbuild module. synetbuild -i your_path/species_list -d your_pep_bed_path -o your_output_path You can input some additional options to adjust the parameters for building the network. synetbuild -i your_path/species_list -d your_pep_bed_path -o your_output_path -k 5 -s 5 -m 10 -p 4 -D -T If you enter the above parameters, a collinear network will be constructed with the top 5 results hit by blastp, Minimum 5 of Anchors for a synteny block, and Maximum 10 of Genes allowed as the GAP between Anchors as parameters, and 4 threads will be used for blastp. Inputting will run MCScanX's duplicate_gene_classifier module, and inputtingwill run the detectability collineear_tandem_arrays module, which can help you better search for tandem genes. Detailed help information can be viewed through -D-Tsynetbuild -h After the step is executed, you will receive a SynNet file, which is the total network file and will be used for subsequent analysis. Step 4: Extract the networks that interest you Extracting subnetworks using the synetfind module. Take the SynNet file obtained in the previous step as input for , use input your protein model file , and you will get a network composed of nodes hit by the model.-n-m synetfind -i your_path/species_list -m your_path/hmm_file -d your_pep_bed_path -n your_path/SynNet_file -o your_output_path You can input the threshold of E-value through to make the search conditions more stringent or relaxed (default is 0.001).-E synetfind -i your_path/species_list -m your_path/hmm_file -d your_pep_bed_path -n your_path/SynNet_file -o your_output_path -E 0.01 If you have a specific list of IDs: synetfind -l your_path/your_id_list_file -n your_path/SynNet_file -o your_output_path Detailed help information can be viewed through .synetfind -h After the step is executed, you will receive a cleaned-network file, this is a two column file composed of nodes hit by the model. At the same time, you will receive a SynNet_f file containing collinearity information for all species. Subsequent modules require the input of these two files. 此时已经进行第3步即构建共线性网络,解释得到的文件以及下一步怎么做
09-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值