河南省第十一届ACM大学生程序设计竞赛——F-Gene mutation

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40788630/article/details/88876435

题目描述:

Gene mutation is the sudden and inheritable mutation of genomic DNA molecules. From the molecular level, gene mutation refers to the change of the composition or sequence of base pairs in the structure of a gene. Although the gene is very stable, it can reproduce itself accurately when the cell divides. Under certain conditions, the gene can also suddenly change from its original existence to another new form of existence.

A genome sequence might provide answers to major questions about the biology and evolutionary history of an organism. A 2010 study found a gene sequence in the skin of cuttlefish similar to those in the eye’s retina. If the gene matches, it can be used to treat certain diseases of the eye.

A gene sequence in the skin of cuttlefish is specified by a sequence of distinct integers (Y1,Y2, …Yc). it may be mutated. Even if these integers are transposed ( increased or decreased by a common amount ) , or re-ordered , it is still a gene sequence of cuttlefish. For example, if "4 6 7" is a gene sequence of cuttlefish, then "3 5 6" (-1), "6 8 9" ( +2), "6 4 7" (re-ordered), and "5 3 6" (transposed and re-ordered) are also ruminant a gene sequence of cuttlefish.

Your task is to determine that there are several matching points at most in a gene sequence of the eye’s retina (X1,X2, …, Xn)

输入描述:

The first line of the input contains one integer T, which is the number of  test cases (1<=T<=5).  Each test case specifies:
* Line 1:       n                     ( 1 ≤ n ≤ 20,000 )
* Line 2:       X1  X2… Xn   ( 1 ≤ Xi ≤ 100    i=1…. n)
* Line 3:       c                     ( 1 ≤ c  ≤ 10 )
* Line 4:       Y1  Y2… Yc   ( 1 ≤ Yi ≤ 100    i=1…. c)

输出描述:

For each test case generate a single line:  a single integer that there are several matching points. The matching gene sequence can be partially overlapped

样例输入:

复制

1
6
1 8 5 7 9 10
3
4 6 7

样例输出:

2

这一题解决方法很简单,首先将c数组排序后,求得每连续两个数值之间的差。

然后遍历n数组,从0至(n-c+1)依次遍历,每次往后取c个数,取出的c个数从大到小排序,排序后求出每连续两个数值之间的差,然后和c数组进行比较,若完全一致则证明这c个数是可行的

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int t,n,c,nl[20010],cl[11],sum;
	cin>>t;
	while(t--){
		memset(nl,0,sizeof(nl));//每一轮都初始化两个数组 
		memset(cl,0,sizeof(cl));
		sum=0;
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>nl[i];
		}
		cin>>c;
		int date[c];//用来存放临时数据 
		for(int i=0;i<c;i++){
			cin>>cl[i];
		}
		sort(cl,cl+c);//将数组排序;
		for(int i=c-1;i>0;i--){
			cl[i]-=cl[i-1];//将cl[i]更新为与前一位的差 
		} 
		cl[0]=0;
		for(int i=0;i<n-c+1;i++){
			for(int j=i;j<i+c;j++){//从i这一点往后取c个数, 
				date[j-i]=nl[j];
			}
			sort(date,date+c);
			int bj=1;//用来标记 
			for(int j=c-1;j>0;j--){ //若date数组每一位和前一位只差等于cl数组的值,证明可行,若有一位不同则不可行 
				if(date[j]-date[j-1]!=cl[j])bj=0;
			}
			if(bj)sum++; 
		}
		cout<<sum<<endl;
	} 
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40788630/article/details/88876435