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)\)扫一边顺便记录最大最小值即可

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <cmath>
  7. #define RG register
  8. #define il inline
  9. #define iter iterator
  10. #define Max(a,b) ((a)>(b)?(a):(b))
  11. #define Min(a,b) ((a)<(b)?(a):(b))
  12. using namespace std;
  13. const int N=3005;
  14. int p[N],a[N],b[N],n;
  15. void work()
  16. {
  17. for(int i=1;i<=n;i++)scanf("%d",&b[i]),p[b[i]]=i;
  18. for(int i=1;i<=n;i++){
  19. scanf("%d",&a[i]);
  20. a[i]=p[a[i]];
  21. }
  22. int ans=0,l,r;
  23. for(int i=1;i<=n;i++){
  24. l=r=a[i];
  25. for(int j=i+1;j<=n;j++){
  26. l=Min(l,a[j]);r=Max(r,a[j]);
  27. if(r-l==j-i)ans++;
  28. }
  29. }
  30. printf("%d\n",ans);
  31. }
  32. int main()
  33. {
  34. while(~scanf("%d",&n) && n)work();
  35. return 0;
  36. }

UVA 1481 Genome Evolution的更多相关文章

  1. adaptation|domestication|genome evolution|convergent evolution|whole-genome shotgun sequencing|IHGSC

    Dissecting evolution and disease using comparative vertebrate genomics-online 因为基因组不是独一无二的,同时人类基因组可以 ...

  2. UVALive 5052 Genome Evolution ——(xjbg)

    本以为这题n=3000,随便n方一下就能过.于是我先枚举长度len再枚举起点,不断增加新的点并删除原来的点,判断在b中的r-l+1是不是等于len即可,这个过程显然要用set维护比较方便,但是貌似卡了 ...

  3. 斯坦福CS课程列表

    http://exploredegrees.stanford.edu/coursedescriptions/cs/ CS 101. Introduction to Computing Principl ...

  4. 差分进化算法 DE-Differential Evolution

    差分进化算法 (Differential Evolution)   Differential Evolution(DE)是由Storn等人于1995年提出的,和其它演化算法一样,DE是一种模拟生物进化 ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. python简单路由系统

    # 输入模块名/函数 url = input('请输入网址:') module,func = url.split('/') m = __import__('lib.'+module,fromlist= ...

  2. python全栈开发-Day13 内置函数

    一.内置函数 注意:内置函数id()可以返回一个对象的身份,返回值为整数. 这个整数通常对应与该对象在内存中的位置,但这与python的具体实现有关,不应该作为对身份的定义,即不够精准,最精准的还是以 ...

  3. nyoj 仿射密码

    仿射密码 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 仿射密码是替换密码的另一个特例,可以看做是移位密码和乘数密码的结合.其加密变换如下: E(m)=(k1*m+k2) ...

  4. 调用WCF时,调用已超过传入消息(65536)的最大消息大小配额。若要增加配额,请使用相应绑定。

    解决方案: 其实只要在客户端配置文件中加上如下紫色粗体属性( maxReceivedMessageSize): <?xml version="1.0" encoding=&q ...

  5. N阶台阶问题(详解)

    原创 问题描述: 有N阶台阶,每一步可以走1步台阶或者2步台阶,求出走到第N阶台阶的方法数. 解题思路: 类似于建立树的过程 1 2 1 2   1 2  1        2      1    2 ...

  6. LightningChart最新版 v.8.3 全新发布,新功能使用教程。

    LightningChart最新版v.8.3全新发布,主要介绍以下五个新功能及使用教程.   1. 网格模型,三角鼠标追踪 Tracing MeshModels with mouse. Traced ...

  7. python入门(14)定义函数和接收返回值

    定义函数: 定义一个求绝对值的my_abs函数为例: def my_abs(x): if x >= 0: return x else: return -x 如果没有return语句,函数执行完毕 ...

  8. 如何修改chrome记住密码后自动填充表单的黄色背景 ?

    input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill { background-color: rgb(2 ...

  9. EasyUI combobox下拉多选框的实现

    combobox实现下拉列表多选, 效果如下

  10. leetcode算法:Island Perimeter

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...