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 ...
随机推荐
- python性能分析--cProfile
Python标准库中提供了三种用来分析程序性能的模块,分别是cProfile, profile和hotshot,另外还有一个辅助模块stats.这些模块提供了对Python程序的确定性分析功能,同时也 ...
- JAVA_SE基础——14.循环结构语句
建议有些基础的同学阅读,0基础可能会有些困难(最好看正文配合基础课本的例子) 所谓循环语句主要就是在满足条件的情况下反复执行某一个操作.Java提供了3种常用的循环语句,分别为for循环语句.whil ...
- LeetCode & Q219-Contains Duplicate II
Array Hash Table Description: Given an array of integers and an integer k, find out whether there ar ...
- MySQL ID排序乱了的解决办法
可能在整理表中数据的时候删除了某一行数据,导致ID空缺,下面是我用到的解决办法:(请先备份,MySQL备份方法见 MySQL->MySQL备份) 使用ALTER DROP删除原有的ID字段: A ...
- python中的赋值与深浅拷贝
Python当中对于拷贝,分为两种类型.一种是数字和字符串,另一种就是列表.元组.字典等其他类型了. 一.数字和字符串的拷贝 1.赋值 举个栗子: a1 = 123123 a2 = 123123 # ...
- 阿里云API网关(12)为员工创建子账号,实现分权管理API:使用RAM管理API
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- 启动Eclipse时An internal error occurred during: "Initializing Java Tooling".错误
解决方法一 重置窗口布局: windows > perspective > reset perspective 解决方法二: 如果上述方法不好使,采用下面的这种方法: 删除workspac ...
- PyCharm设置仿sublime配色__Py版本2018.1
Talk is cheap~ Let's do this! 配色效果图: 在网上搜了一大圈,没有能看的一清二楚的,注意本次Pycharm版本是2018.1,如果是别的版本,基本设置也是大同小异~ 看图 ...
- SourceTree 03 - 跳过账号登录直接进入主界面
SourceTree系列第1篇 SourceTree 01 - git 客户端介绍(http://www.cnblogs.com/geaosu/p/8807666.html) SourceTree系列 ...
- html框架练习-基本网页制作
index.html <html> <head> <title>html框架</title> <meta charset="utf-8& ...