UVA 1481 Genome Evolution
Xi, a developmental biologist is working on developmental distances of chromosomes. A chromosome,
in the Xi’s simplistic view, is a permutation from n genes numbered 1 to n. Xi is working on an
evolutionary distance metric between two chromosomes. In Xi’s theory of evolution any subset of genes
lying together in both chromosomes is a positive witness for chromosomes to be similar.
A positive witness is a pair of sequence of the same length A and A ′ , where A is a consecutive
subsequence of the first chromosome, A ′ is a consecutive subsequence of the second chromosome, and A
is a permutation of A ′ . The goal is to count the number of positive witnesses of two given chromosomes
that have a length greater than one.
题目大意:给出A,B两个序列,设a为A的一个连续子序列,b为B的一个连续子序列,求a,b中元素相同的(a,b)对数 如{1,3,2}和{3,1,2}相等
解题报告:应该写的是正解吧,毕竟这么简短,首先我们把B数组的\(b_i\)替换成\(b_i\)在A数组中的位置,那么显然对于新的B数组,如果一个连续的子序列中正好对应某个区间内的连续一段,那么就符合条件,如{2,4,3}就符合条件,因为对于[2,4]这个连续区间,所以就是怎么求这样的子序列,本人开始想树状数组维护每个数出现的次数,仿佛还需要卡常,上波厕所突然想到如果区间长度L等于该区间数最大值和最小值差即可满足条件,厕所果然是思维圣殿,然后\(O(n^2)\)扫一边顺便记录最大最小值即可
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=3005;
int p[N],a[N],b[N],n;
void work()
{
for(int i=1;i<=n;i++)scanf("%d",&b[i]),p[b[i]]=i;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
a[i]=p[a[i]];
}
int ans=0,l,r;
for(int i=1;i<=n;i++){
l=r=a[i];
for(int j=i+1;j<=n;j++){
l=Min(l,a[j]);r=Max(r,a[j]);
if(r-l==j-i)ans++;
}
}
printf("%d\n",ans);
}
int main()
{
while(~scanf("%d",&n) && n)work();
return 0;
}
UVA 1481 Genome Evolution的更多相关文章
- adaptation|domestication|genome evolution|convergent evolution|whole-genome shotgun sequencing|IHGSC
Dissecting evolution and disease using comparative vertebrate genomics-online 因为基因组不是独一无二的,同时人类基因组可以 ...
- UVALive 5052 Genome Evolution ——(xjbg)
本以为这题n=3000,随便n方一下就能过.于是我先枚举长度len再枚举起点,不断增加新的点并删除原来的点,判断在b中的r-l+1是不是等于len即可,这个过程显然要用set维护比较方便,但是貌似卡了 ...
- 斯坦福CS课程列表
http://exploredegrees.stanford.edu/coursedescriptions/cs/ CS 101. Introduction to Computing Principl ...
- 差分进化算法 DE-Differential Evolution
差分进化算法 (Differential Evolution) Differential Evolution(DE)是由Storn等人于1995年提出的,和其它演化算法一样,DE是一种模拟生物进化 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
随机推荐
- tableView//collectionView加载时的动画
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:( ...
- nyoj 黑色帽子
黑色帽子 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 最近发现了一个搞笑的游戏,不过目前还没玩过.一个舞会上,每个人头上都戴着一顶帽子,帽子只有黑 ...
- Linux的打印rpm包的详细信息的shell脚本
#!/bin/bash # list a content summary of a number of RPM packages # USAGE: showrpm rpmfile1 rpmfile2 ...
- URL编码和Base64编码 (转)
我们经常会遇到所谓的URL编码(也叫百分号编码)和Base64编码. 先说一下Bsae64编码.BASE64编码是一种常用的将二进制数据转换为64个可打印字符的编码,常用于在通常处理文本数据 ...
- 怎样使用下载的bootstrap模板?
核心文件bootstarp.css和bootstarp.js导入到页面,然后看着官网的代码复制进去用就可以了.网上是有不少教程的.实际上就是加class 属性 ,如:http://www.runoob ...
- MicrosoftWebInfrastructure 之坑
从svn下载下来的项目,还原提示缺少MicrosoftWebInfrastructure 包 网上大多数解决方法 PM> Install-Package Microsoft.Web.Inf ...
- linux搭建django项目基本步骤
一 linux下django基本项目搭建流程:M model 用于与数据库交互V view 接受前台请求 调用model获取结果,调用T获取页面,返回给前台T template 接受view的要求 生 ...
- POJ-1860 Currency Exchange---Bellman-Ford判断正环
题目链接: https://vjudge.net/problem/POJ-1860 题目大意: 我们的城市有几个货币兑换点.让我们假设每一个点都只能兑换专门的两种货币.可以有几个点,专门从事相同货币兑 ...
- 02、NetCore2.0优化之Nuget包
02.NetCore2.0优化之Nuget包 在NetCore2.0中的包是如何管理的?如何存储的?微软做了哪些优化工作? -------------------------------------- ...
- 学习React系列(六)——更新dom细节于原理
React更新dom的依据: 1.不同类型的elements会产生不同的树 2.通过render方法中包含key属性的子元素,开发者可以示意哪些子元素可能是稳定的. 更新过程: 一.根元素类型不同:旧 ...