寒假训练。3.1。(听说是浙大的题)J - Virus Replication

Some viruses replicate by replacing a piece of DNA in a living cell with a piece of DNA that the virus carries with it. This makes the cell start to produce viruses identical to the original one that infected the cell. A group of biologists is interested in knowing how much DNA a certain virus inserts into the host genome. To find this out they have sequenced the full genome of a healthy cell as well as that of an identical cell infected by a virus.

 

The genome turned out to be pretty big, so now they need your help in the data processing step. Given the DNA sequence before and after the virus infection, determine the length of the smallest single, consecutive piece of DNA that can have been inserted into the first sequence to turn it into the second one. A single, consecutive piece of DNA might also have been removed from the same position in the sequence as DNA was inserted. Small changes in the DNA can have large effects, so the virus might insert only a few bases, or even nothing at all.

Input

The input consists of two lines containing the DNA sequence before and after virus infection respectively. A DNA sequence is given as a string containing between 1 and 105105 upper-case letters from the alphabet {A, G, C, T}.

Output

Output one integer, the minimum length of DNA inserted by the virus.

Sample Input 1Sample Output 1
AAAAA
AGCGAA
3
Sample Input 2Sample Output 2
GTTTGACACACATT
GTTTGACCACAT
4

 

 

 

 

这道题的话,在打比赛的时候没有写出来。

心态很崩当时,前面水题都WA了很多发。

不过后来讲题的时候大喊真TM简单,结果最后自己试的时候还是踩了很多坑。

题意:

大概就是病毒对细胞进行改造,输入的第一行是细胞原来的DNA,第二行是改造之后的DNA。

要求输出病毒到底输入了多少碱基;

坑点:

1、当所给出的DNA碱基完全相同。2、莫一行碱基与另一行的部分完全相同。3、两行交换位置,输出完全不同。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<cstdlib>
#include<ctype.h>
using namespace std;
typedef long long ll;
#define pi 3.14159265358979323846264338327
#define INF 0x3f3f3f3f
#define maxn 200100
#define lcm 21252

char a[maxn], b[maxn];
int main() {
	char c;
	int wei = -1, tou = -1;
	int DNA = 0;
	scanf("%s", a);
	getchar();
	scanf("%s", b);
	int la = strlen(a);
	int lb = strlen(b);
	for (int i = 0; i < min(la, lb); ++i) {
		if (a[la - i - 1] != b[lb - i - 1]) {
			wei = i;
			break;
		}
	}
	for (int i = 0; i < min(la, lb); ++i) {
		if (a[i] != b[i]) {
			tou = i;
			break;
		}
	}
	if (wei == -1 || tou == -1) {
		if (la > lb) {
			DNA = 0;
		}
		else {
			DNA = lb - la;
		}
	}
	else {
		DNA = lb - tou - wei;
	}
	printf("%d\n", DNA);
	system("pause");
}

  这是我12/13的代码,准确的来说是WA的代码QAQ。一直不知道错在何方。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<cstdlib>
#include<ctype.h>
using namespace std;
typedef long long ll;
#define pi 3.14159265358979323846264338327
#define INF 0x3f3f3f3f
#define maxn 200100
#define lcm 21252

char a[maxn], b[maxn];
int main() {
	char c;
	int wei = -1, tou = -1;
	int DNA = 0;
	scanf("%s", a);
	getchar();
	scanf("%s", b);
	int la = strlen(a);
	int lb = strlen(b);
	for (int i = 0; i < min(la, lb); ++i) {
		if (a[la - i - 1] != b[lb - i - 1]) {
			wei = i;
			break;
		}
	}
	for (int i = 0; i < min(la, lb); ++i) {
		if (a[i] != b[i]) {
			tou = i;
			break;
		}
	}
	if (wei == -1 || tou == -1) {
		if (la > lb) {
			DNA = 0;
		}
		else {
			DNA = lb - la;
		}
	}
	else {
		DNA = lb - tou - wei;
	}
	if (DNA < 0)DNA = 0;
	printf("%d\n", DNA);
	system("pause");
}

  这是AC代码,我也不知道为啥加一个DNA必须是正数的设定就对了

很玄学;

 

posted @ 2018-03-01 20:34  TRACYlegolas  阅读(280)  评论(0编辑  收藏  举报