ZOJ 1076Gene Assembly(很简单的贪心)
2014-01-12 15:19
267 查看
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
题目大意:给了一连串的DNA蛋白质之类的。。。大致意思就是把他们首尾连接拼起来,使得长度最长。类似很久以前做的看电视节目尽量多的贪心,直接对结束时间排序即可。然后再贪心。。
我的第33道题,oh my god!!!
AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int ans[1005];
struct node
{
int sta;
int en;
int pos;
}nod[1005];
int cmp(node p1,node p2)
{
if(p1.en<=p2.en) return 1;
return 0;
}
int main()
{
int n,i;
int t,p;
while(cin>>n&&n)
{
for(i=1;i<=n;i++)
{
scanf("%d%d",&nod[i].sta,&nod[i].en);
nod[i].pos=i;
}
sort(nod+1,nod+1+n,cmp);
t=0; p=nod[1].en;
ans[t++]=nod[1].pos;
//cout<<nod[1].pos<<" ***"<<endl;
for(i=2;i<=n;i++)
{
if(nod[i].sta>p)
{
p=nod[i].en;
ans[t++]=nod[i].pos;
}
}
cout<<ans[0];
for(i=1;i<t;i++)
cout<<" "<<ans[i];
cout<<endl;
}
return 0;
}
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
题目大意:给了一连串的DNA蛋白质之类的。。。大致意思就是把他们首尾连接拼起来,使得长度最长。类似很久以前做的看电视节目尽量多的贪心,直接对结束时间排序即可。然后再贪心。。
我的第33道题,oh my god!!!
AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int ans[1005];
struct node
{
int sta;
int en;
int pos;
}nod[1005];
int cmp(node p1,node p2)
{
if(p1.en<=p2.en) return 1;
return 0;
}
int main()
{
int n,i;
int t,p;
while(cin>>n&&n)
{
for(i=1;i<=n;i++)
{
scanf("%d%d",&nod[i].sta,&nod[i].en);
nod[i].pos=i;
}
sort(nod+1,nod+1+n,cmp);
t=0; p=nod[1].en;
ans[t++]=nod[1].pos;
//cout<<nod[1].pos<<" ***"<<endl;
for(i=2;i<=n;i++)
{
if(nod[i].sta>p)
{
p=nod[i].en;
ans[t++]=nod[i].pos;
}
}
cout<<ans[0];
for(i=1;i<t;i++)
cout<<" "<<ans[i];
cout<<endl;
}
return 0;
}
相关文章推荐
- zoj 3721 Final Exam Arrangement【贪心】
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- ZOJ - 3953Intervals(贪心)
- ZOJ 3908 Number Game (贪心+二分+multiset)
- zoj3953 贪心 training 3
- zoj 2921 Stock(贪心)
- ZOJ 2315 New Year Bonus Grant(贪心)
- ZOJ 1076 Gene Assembly 贪心
- ZOJ 1877 Bridge(贪心)
- ZOJ 3829 贪心 思维题
- ZOJ 3721 Final Exam Arrangement 解题报告 (贪心)
- zoj 3870 贪心
- zoj 3721 Final Exam Arrangement【贪心】
- zoj 1029 贪心
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- ZOJ 2315 New Year Bonus Grant(贪心)
- ZOJ 3715 - Kindergarten Election 枚举后贪心...
- hdu 4424 & zoj 3659 Conquer a New Region (并查集 + 贪心)
- ZOJ 3721 Final Exam Arrangement (贪心)
- ZOJ3820 Building Fire Stations(贪心)