ZOJ 1076 Gene Assembly
2016-03-08 22:44
323 查看
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
把每对数看作线段坐标,那么题意就是要找不重合的最大线段个数。刚开始用开始的坐标排序,绕了弯路。用结束的坐标排序就简单多了。不过代码还是很丑,应该用struct,不过懒得改了。
#include <iostream>
#define MAX 1001
using namespace std;
bool is_bigger(int* inst1, int* inst2){
if(inst1[1] != inst2[1])
return (inst1[1] > inst2[1]);
else
return (inst1[0] > inst2[0]);
}
int main(){
int n_inst, temp, inst[MAX][3], sorted_inst[MAX][3], mark[MAX], end; //inst: (start pos, end pos, index)
cin>>n_inst;
while(n_inst > 0){
for(int i = 0; i < n_inst; i++){
cin>>inst[i][0]>>inst[i][1];
inst[i][2] = i + 1;
}
for(int i = 0; i < n_inst; i++){ // 排序
int count = 0;
for(int j = n_inst - 1; j >= 0; j--){
if(is_bigger(inst[i], inst[j]))
count++;
}
mark[i] = count;
}
for(int i = 0; i < n_inst; i++){
sorted_inst[mark[i]][0] = inst[i][0];
sorted_inst[mark[i]][1] = inst[i][1];
sorted_inst[mark[i]][2] = inst[i][2];
}
// cout<<endl;
// for(int i = 0; i < n_inst; i++)
// cout<<sorted_inst[i][2]<<' '<<sorted_inst[i][0]<<' '<<sorted_inst[i][1]<<endl;
cout<<sorted_inst[0][2];
end = sorted_inst[0][1];
for(int i = 1; i < n_inst; i++){
if(sorted_inst[i][0] > end){
cout<<' '<<sorted_inst[i][2];
end = sorted_inst[i][1];
}
}
cout<<endl;
cin>>n_inst;
}
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
把每对数看作线段坐标,那么题意就是要找不重合的最大线段个数。刚开始用开始的坐标排序,绕了弯路。用结束的坐标排序就简单多了。不过代码还是很丑,应该用struct,不过懒得改了。
#include <iostream>
#define MAX 1001
using namespace std;
bool is_bigger(int* inst1, int* inst2){
if(inst1[1] != inst2[1])
return (inst1[1] > inst2[1]);
else
return (inst1[0] > inst2[0]);
}
int main(){
int n_inst, temp, inst[MAX][3], sorted_inst[MAX][3], mark[MAX], end; //inst: (start pos, end pos, index)
cin>>n_inst;
while(n_inst > 0){
for(int i = 0; i < n_inst; i++){
cin>>inst[i][0]>>inst[i][1];
inst[i][2] = i + 1;
}
for(int i = 0; i < n_inst; i++){ // 排序
int count = 0;
for(int j = n_inst - 1; j >= 0; j--){
if(is_bigger(inst[i], inst[j]))
count++;
}
mark[i] = count;
}
for(int i = 0; i < n_inst; i++){
sorted_inst[mark[i]][0] = inst[i][0];
sorted_inst[mark[i]][1] = inst[i][1];
sorted_inst[mark[i]][2] = inst[i][2];
}
// cout<<endl;
// for(int i = 0; i < n_inst; i++)
// cout<<sorted_inst[i][2]<<' '<<sorted_inst[i][0]<<' '<<sorted_inst[i][1]<<endl;
cout<<sorted_inst[0][2];
end = sorted_inst[0][1];
for(int i = 1; i < n_inst; i++){
if(sorted_inst[i][0] > end){
cout<<' '<<sorted_inst[i][2];
end = sorted_inst[i][1];
}
}
cout<<endl;
cin>>n_inst;
}
return 0;
}
相关文章推荐
- 提高C++程序运行效率的10个简单方法
- [BZOJ1797][Ahoi2009]Mincut 最小割 做题笔记
- visio2013画图时两条直线交叉 如何让它不弯曲
- appium V1.5.x变化
- numbers-everyone-should-know
- 数据归一化的两种常用方法
- android项目的文件介绍
- touch 修改文件时间戳,或者新建一个不存在的文件 - 副本
- sleep和wait的区别
- 集群管理和分布式任务 Apache helix
- JavaScript 中的原型声明和用法总结
- pwd 查看”当前工作目录“的完整路径
- 前端渲染:服务器渲染 or 客户端渲染
- O2O、C2C、B2B、B2C的区别
- 基于POI的导入导出Excel
- Bind 视图
- 动态内存分配和指针
- UIButton 的基本用法
- python笔记 爬虫经常出现的错误UnicodeEncodeError
- mkdir 创建文件夹或者目录