您的位置:首页 > 其它

ZOJ-1076 Gene Assembly

2013-05-12 09:28 260 查看
Gene Assembly

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Statement of the Problem

With the large amount of genomic DNA sequence data being made available, it is becoming more important to find genes (parts of the genomic DNA which are responsible for the synthesis of proteins) in these sequences. It is known that for eukaryotes (in contrast to prokaryotes) the process is more complicated, because of the presence of junk DNA that interrupts the coding region of genes in the genomic sequence. That is, a gene is composed by several pieces (called exons) of coding regions. It is known that the order of the exons is maintained in the protein synthesis process, but the number of exons and their lengths can be arbitrary.

Most gene finding algorithms have two steps: in the first they search for possible exons; in the second they try to assemble a largest possible gene, by finding a chain with the largest possible number of exons. This chain must obey the order in which the exons appear in the genomic sequence. We say that exon i appears before exon j if the end of i precedes the beginning of j.

The objective of this problem is, given a set of possible exons, to find the chain with the largest possible number of exons that cound be assembled to generate a gene.

Input Format

Several input instances are given. Each instance begins with the number 0 < n < 1000 of possible exons in the sequence. Then, each of the next n lines contains a pair of integer numbers that represent the position in which the exon starts and ends in the genomic sequence. You can suppose that the genomic sequence has at most 50000 basis. The input ends with a line with a single 0.

Output Format

For each input instance your program should print in one line the chain with the largest possible number of exons, by enumerating the exons in the chain. If there is more than one chain with the same number of exons, your program can print anyone of them.

Sample Input

6

340 500

220 470

100 300

880 943

525 556

612 776

3

705 773

124 337

453 665

0

Sample Output

3 1 5 6 4

2 3 1

对后面的数据快速排序,然后筛选

#include <stdio.h>

struct node {
int f;
int e;
int id;
};

void QuickSort(struct node *, int s, int e);
int process(struct node *, int i, int j);
int main()
{
int n, i, count[1001], j, t;
struct node exons[1000];
while(scanf("%d", &n) && n) {
for(i = 0; i < n; i++) {
exons[i].id= i;
scanf("%d%d", &exons[i].f, &exons[i].e);
}
QuickSort(exons, 0, n-1);
t = 0;
count[t++] = exons[0].id;
/*for(i = 0; i < n; i++) {
printf("%d %d\n", exons[i].f, exons[i].e);
}*/
for(i = 1, j = 0; i < n; i++) {
if(exons[i].f >= exons[j].e) {
count[t++] = exons[i].id;
j = i;
}
}
printf("%d", count[0]+1);
for(i = 1; i < t; i++) {
printf(" %d", count[i]+1);
}
printf("\n");
}
return 0;
}

void QuickSort(struct node *array, int s, int e)
{
int k;
if(s < e) {
k = process(array, s, e);
QuickSort(array, s, k-1);
QuickSort(array, k+1, e);
}
}

int process(struct node *array, int i, int j)
{
struct node k;
k = array[i];
while(i < j) {
while(i < j && array[j].e >= k.e) {
j--;
}
array[i] = array[j];
while(i < j && array[i].e <= k.e) {
i++;
}
array[j] = array[i];
}
array[i] = k;
return i;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM解题报告 贪心