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 ...
随机推荐
- 要学好JAVA要注意些什么?
从自学开始到参加系统的学习JAVA已经差不多有1个月了的时间了,在这段时间以前我也和很多人一样在网上盲目的搜罗一些视频来自己啃,随着时间的积累,对JAVA的认识也有了一定的提升,之前可能因为在IT咨询 ...
- Hibernate之深入Hibernate的配置文件
1.创建Configuration类的对象 Configuration类的对象代表了应用程序到SQL数据库的映射配置.Configuration类的实例对象,提供一个buildSessionFacto ...
- 微信小程序轮播图
swiper标签 <!--index.wxml--> <swiper class="swiper" indicator-dots="true" ...
- mongodb 定时备份
通过centos 脚步来执行备份操作,使用crontab实现定时功能,并删除指定天数前的备份 具体操作: 1.创建Mongodb数据库备份目录 mkdir -p /home/backup/mongod ...
- java截取一个字符串正数或倒数某个特定字符前后的内容
取出正数第二个“.”后面的内容 public class TestCode { public static void main(String[] args) { String str ="2 ...
- LeetCode & Q169-Majority Element-Easy
Array Divide and Conquer Bit Manipulation Description: Given an array of size n, find the majority e ...
- pymysql安装和使用
一.pymysql安装 安装mymysql前请确认python环境已经准备好,在之前的博文http://www.cnblogs.com/newzol/p/8682176.html有说明pythonwe ...
- 新特性GTID
什么是GTID 每提交一个事务,当前的执行过程都会拿到一个唯一的标识符,此标识符不仅对其源mysql 实列是唯一的而在给定的复制环境中的所有mysql 实列也是唯一的,所哟的事务与其GTID 之间都是 ...
- Python内置函数(16)——ord
英文文档: ord(c) Given a string representing one Unicode character, return an integer representing the U ...
- 使用Python3爬虫抓取网页来下载小说
很多时候想看小说但是在网页上找不到资源,即使找到了资源也没有提供下载,小说当然是下载下来用手机看才爽快啦! 于是程序员的思维出来了,不能下载我就直接用爬虫把各个章节爬下来,存入一个txt文件中,这样, ...