UVaLive LA 5052 UVa 1481 - Genome Evolution (很巧妙的思维)
2014-07-22 21:50
309 查看
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.
(2
n
3000).
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.
题意:
给出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) 那么这个就是一个解 因为没有重复元素!
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.
Input
There are several test case in the input. Each test case starts with a line containing the number of genes(2
n
3000).
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 4 3 2 1 5 4 0
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 WIN typedef __int64 LL; #define iform "%I64d" #define oform "%I64d\n" #define oform1 "%I64d" #else typedef 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 4356 - Fire-Control System (扫描法 思维)
- UVALive - 7501 思维 +二分
- UVALive 3942 (LA 3492) Remember the Word Trie树 + 记忆化搜索
- LA 4329/uvalive 4329 (树状数组)
- UVALive 6117 (LA 6117) Pole Arrangement 动态规划
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
- UVALive - 7501 思维 +二分
- UVaLive LA 4726 UVa 1451 - Average (子序列最大平均数 数形结合 斜率优化 单调队列)
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
- 树状数组(LA4329,UVaLive4329,Ping pong)
- UVaLive 2678(LA)Subsequence SEERC 2006 题解
- UVALive 6694 - Toy Boxes(思维+二分)
- UVALive - 7501 思维 +二分
- UVALive 5873 (几何+思维)
- UVALive 7512 November 11th(模拟, 思维)
- UVALive 7147 World Cup ——思维题
- UVALive 6588 Crane (思维+贪心) -- 解题报告
- UVALive - 7501 思维 +二分
- UVALive 7417 思维
- UVALive 4513 (LA 4513) Stammering Aliens 后缀数组 或 hash