10020 - Minimal coverage

本文介绍了一种解决区间覆盖问题的方法,通过将区间按左端点排序并选取最大右端点来完成覆盖,适用于[0,M]区间的最少坐标覆盖问题。
/*
区间覆盖问题,一次AC

题意:使用题中所给坐标[Li,Ri]覆盖[0,M],如果不能覆盖输出0,如果可以,输出使用最少坐标的情况,并输出其序列,要求按Li进行排序。

思路:其中刘汝佳书中有这道题的详细思路,但是我感觉实现起来蛮复杂,所以使用自己的思路进行解答。
首先按Li对坐标进行排序,找出其中Li<=l的情况,选择其中Ri最大的那个坐标,判断是否满足Ri>l如果满足,则转变为对[Ri,M]的覆盖,如果不满足则结束。贪心思路即:按Li进行排序,寻找其中Ri最大的那种情况。
*/
#include <cstdio>
#include <cstdlib>
const int nMax=100007;
struct Node
{
	int Li;
	int Ri;
	Node(int Li,int Ri):Li(Li),Ri(Ri){}
	Node(){}
}A[nMax];
int n;
int ans[nMax],m;
bool ok;
int cmp(const void *a,const void *b)
{
	Node *pa=(Node *)a;
	Node *pb=(Node *)b;
	return pa->Li-pb->Li;
}
void cover(int l,int r,int cur)
{
	if(l >= r)
	{
		ok=1;
		return;
	}
	int i;
	for(i = cur; i < n; i++)
		if(A[i].Li > l)
			break;
	int j;
	int max=cur;
	for(j = cur + 1; j < i; j++)
		if(A[j].Ri > A[max].Ri)
			max=j;
	if(A[max].Ri > l)
	{
		ans[m++]=max;
		cover(A[max].Ri,r,i);
	}
	else
		return;
}
int main()
{
	//freopen("f://data.in","r",stdin);
	int T,M;
	scanf("%d",&T);
	while(T--)
	{
		ok=false;
		m=0;n=0;
		scanf("%d",&M);
		int a,b;
		while(scanf("%d %d",&a,&b)!=EOF)
		{
			if(a==0 && b==0) break;
			A[n]=Node(a,b);
			n++;
		}
		qsort(A,n,sizeof(A[0]),cmp);
		cover(0,M,0);
		if(ok)
		{
			printf("%d\n",m);
			for(int i=0;i<m;i++)
				printf("%d %d\n",A[ans[i]].Li,A[ans[i]].Ri);
		}
		else
			printf("0\n");
		if(T) printf("\n");
	}
	return 0;
}

Error in argument: the --format gff3 is not currently supported. Please contact ANNOVAR developer for adding the support Usage: convert2annovar.pl [arguments] <variantfile> Optional arguments: -h, --help print help message -m, --man print complete documentation -v, --verbose use verbose output --format <string> input format (default: pileup) --includeinfo include supporting information in output --outfile <file> output file name (default: STDOUT) --snpqual <float> quality score threshold in pileup file (default: 20) --snppvalue <float> SNP P-value threshold in GFF3-SOLiD file (default: 1) --coverage <int> read coverage threshold in pileup file (default: 0) --maxcoverage <int> maximum coverage threshold (default: none) --chr <string> specify the chromosome (for CASAVA format) --chrmt <string> chr identifier for mitochondria (default: M) --fraction <float> minimum allelic fraction to claim a mutation (for pileup format) --altcov <int> alternative allele coverage threshold (for pileup format) --allelicfrac print out allelic fraction rather than het/hom status (for pileup format) --species <string> if human, convert chr23/24/25 to X/Y/M (for gff3-solid format) --filter <string> output variants with this filter (case insensitive, for vcf4 format) --confraction <float> minimal fraction for two indel calls as a 0-1 value (for vcf4old format) --allallele print all alleles rather than first one (for vcf4old format) --withzyg print zygosity/coverage/quality when -includeinfo is used (for vcf4 format) --comment keep comment line in output (for vcf4 format) --allsample process all samples in file with separate output files (for vcf4 format) --genoqual <float> genotype quality score threshold (for vcf4 format) --varqual <float> variant quality score threshold (for vcf4 format) --dbsnpfile <file> dbSNP file in UCSC format (for rsid format) --withfreq for --allsample, print frequency information instead (for vcf4 format) --withfilter print filter information in output (for vcf4 format) --seqdir <string> directory with FASTA sequences (for region format) --inssize <int> insertion size (for region format) --delsize <int> deletion size (for region format) --subsize <int> substitution size (default: 1, for region format) --genefile <file> specify the gene file from UCSC (for transcript format) --splicing_threshold <int> the splicing threshold (for transcript format) --context <int> print context nucleotide for indels (for casava format) --avsnpfile <file> specify the avSNP file (for rsid format) --keepindelref keep Ref/Alt alleles for indels (for vcf4 format) Function: convert variant call file generated from various software programs into ANNOVAR input format Example: convert2annovar.pl -format pileup -outfile variant.query variant.pileup convert2annovar.pl -format cg -outfile variant.query variant.cg convert2annovar.pl -format cgmastervar variant.masterVar.txt convert2annovar.pl -format gff3-solid -outfile variant.query variant.snp.gff convert2annovar.pl -format soap variant.snp > variant.avinput convert2annovar.pl -format maq variant.snp > variant.avinput convert2annovar.pl -format casava -chr 1 variant.snp > variant.avinput convert2annovar.pl -format vcf4 variantfile > variant.avinput convert2annovar.pl -format vcf4 -filter pass variantfile -allsample -outfile variant convert2annovar.pl -format vcf4old input.vcf > output.avinput convert2annovar.pl -format rsid snplist.txt -dbsnpfile snp138.txt > output.avinput convert2annovar.pl -format region -seqdir humandb/hg19_seq/ chr1:2000001-2000003 -inssize 1 -delsize 2 convert2annovar.pl -format transcript NM_022162 -gene humandb/hg19_refGene.txt -seqdir humandb/hg19_seq/ Version: $Date: 2018-04-16 00:48:00 -0400 (Mon, 16 Apr 2018) $
最新发布
10-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值