UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
来源:互联网 发布:织梦dedecms5.7 编辑:程序博客网 时间:2024/06/14 16:03
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的两个排列A和B,统计有多少二元组(A',B')满足:A' B' 分别是A B的子序列,且A' B'包含的整数集完全相同 A' B'均应至少包含两个元素
思路:
我没有想出来,看了网上的题解,发现智商是硬伤啊
补充一下大白上面题意 A B序列均没有重复元素 所以才可以这有做
直接枚举A的所有子序列O(n^2) 同时A的子序列subA的元素在B中出现的位置的最大值和最小值
如果位置的最大值和最小值之差+1==len(subA) 那么这个就是一个解 因为没有重复元素!
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>#include <cstring>#include <string>#include <map>#include <cmath>#include <queue>#include <set>using namespace std;//#define WIN#ifdef WINtypedef __int64 LL;#define iform "%I64d"#define oform "%I64d\n"#define oform1 "%I64d"#elsetypedef long long LL;#define iform "%lld"#define oform "%lld\n"#define oform1 "%lld"#endif#define S64I(a) scanf(iform, &(a))#define P64I(a) printf(oform, (a))#define P64I1(a) printf(oform1, (a))#define REP(i, n) for(int (i)=0; (i)<n; (i)++)#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)const int INF = 0x3f3f3f3f;const double eps = 10e-9;const double PI = (4.0*atan(1.0));const int maxn = 3000 + 20;int A[maxn];int B[maxn];int main() { int n; while(scanf("%d", &n) != EOF && n) { for(int i=1; i<=n; i++) scanf("%d", &A[i]); for(int i=1; i<=n; i++) { int t; scanf("%d", &t); B[t] = i; } int ans = 0; for(int i=1; i<n; i++) { int minp = B[A[i]]; int maxp = B[A[i]]; for(int j=i+1; j<=n; j++) { int p = B[A[j]]; minp = min(minp, p); maxp = max(maxp, p); if(maxp - minp == j - i) ans++; } } printf("%d\n", ans); } return 0;}
- UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
- LA 5052 Genome Evolution (思维)
- Uva LA 5052 Genome Evolution
- LA 5052 Genome Evolution -
- LA 5052 Genome Evolution
- UvaLive-5052-Genome Evolution
- UVALive - 5052 Genome Evolution
- UVa 1481 - Genome Evolution
- UVALive - 5052 Genome Evolution 贪心
- uva 1481 - Genome Evolution(暴力)
- UVa 1481 Genome Evolution 解题报告(枚举)
- UVA 1481 - Genome Evolution(枚举技巧)
- UVA - 1481 Genome Evolution 公式+二分
- UVA 1481 Genome Evolution(高效算法优化)
- UVALive5052 Genome Evolution(想法题)
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- Genome Evolution LA5052
- Genome Evolution uvalive5052
- 开博申明
- hduoj2025(查找最大元素)
- AC自动机 总结
- HDU 2191 珍惜现在,感恩生活(动规)
- hdu 1096 a+b问题8 n组数n在前 每组m个m在前 结果后加换行 20140722.cpp
- UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
- cin.clear()和cin.sync
- .svn 文件夹清除工具
- lucene学习笔记-1
- virtualbox下的ubuntu系统中文输入法的安装使用
- 【HDU 4862】Jump【KM】
- 利用画刷将控件界面保存成图片
- OpenCV学习笔记17 OpenCV高级GUI和多媒体模块 HIGHGUI MODULE (一)
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音