UVa 1481 Genome Evolution 解题报告(枚举)
来源:互联网 发布:企业网络宣传语 编辑:程序博客网 时间:2024/06/02 03:38
1481 - Genome Evolution
Time limit: 3.000 seconds
Xi, a developmental biologist is working on developmental distances of chromosomes. A chromosome, in the Xi's simplistic view, is a permutation fromn 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.
Input
There are several test case in the input. Each test case starts with a line containing the number of genes(2n3000). The next two lines contain the two chromosomes, each as a list of positive integers. The input terminates with a line containing ``0'' which should not be processed as a test case.
Output
For each test case, output a single line containing the number of positive witness for two chromosomes to be similar.
Sample Input
4 3 2 1 4 1 2 4 3 5 3 2 1 5 43 2 1 5 40
Sample Output
3 10
题意: 两个1-n的排列,问元素相同的长度大于等于2的连续子序列有多少对。
做法其实很简单,别想太复杂。首先记录排列b中1-n各个数字出现的位置。在排列a中枚举起点,找出相应的在b中的位置。随着排列a元素的增加,更新对应的排列b中的最小位置和最大位置。如果二者长度相等,说明两个子排列元素相等。代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <map>#include <set>#include <string>using namespace std;#define ff(i, n) for(int i=0;i<(n);i++)#define fff(i, n, m) for(int i=(n);i<=(m);i++)#define dff(i, n, m) for(int i=(n);i>=(m);i--)typedef long long LL;typedef unsigned long long ULL;void work();int main(){#ifdef ACM freopen("in.txt", "r", stdin);// freopen("in.txt", "w", stdout);#endif // ACM work();}/*****************************************/int a[3333], b[3333];int pos[3333];void work(){ int n; while(~scanf("%d", &n) && n) { fff(i, 1, n) scanf("%d", a+i); fff(i, 1, n) scanf("%d", b+i), pos[b[i]] = i; int ans = 0; fff(i, 1, n) { int minP = pos[a[i]]; int maxP = pos[a[i]]; fff(j, i+1, n) { int p = pos[a[j]]; minP = min(minP, p); maxP = max(maxP, p); if(maxP - minP == j - i) ans++; } } printf("%d\n", ans); }}
- UVa 1481 Genome Evolution 解题报告(枚举)
- UVA 1481 - Genome Evolution(枚举技巧)
- UVa 1481 - Genome Evolution
- uva 1481 - Genome Evolution(暴力)
- UVA - 1481 Genome Evolution 公式+二分
- UVA 1481 Genome Evolution(高效算法优化)
- Uva LA 5052 Genome Evolution
- UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
- Uva 1352 Colored Cubes 解题报告(枚举+码力)
- Uva 11210 Chinese Mahjong 解题报告(枚举+码力)
- UVa 1382 Distant Galaxy 解题报告(枚举 + 前缀和)
- UVa 1312 Cricket Field 解题报告(枚举 + 离散化)
- UVa 1508 Equipment 解题报告(枚举子集)
- UVa 1523 Helicopter 解题报告(枚举排列)
- UVa 812 - Trade on Verweggistan 解题报告(枚举)
- UVALive5052 Genome Evolution(想法题)
- Genome Evolution LA5052
- UvaLive-5052-Genome Evolution
- Mac下搭建php开发环境
- GTK+扫雷,目标达成,前来汇报,顺带一说按钮上色的疑惑
- 主机域名排序
- Object-c 之 复合与存取
- java处理.net webService传回的DataSet对象
- UVa 1481 Genome Evolution 解题报告(枚举)
- 如何组织你的javascript代码
- libUV写TCPServer
- hdu1285 确定比赛名次(拓扑排序多种方法)
- Swift_10_网络请求
- 归并排序算法
- 编写systemd下服务脚本
- Linux下的输入/输出重定向
- HDU 3642 Get The Treasury