UVa 1481 Genome Evolution 解题报告(枚举)

生物学家Xi在简化视角下研究染色体之间的进化距离,通过计算两个染色体中相同基因序列的连续子序列对数,探讨相似性度量。此算法在生物学与遗传学领域具有重要意义。

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 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.

Input 

There are several test case in the input. Each test case starts with a line containing the number of genes (2$ \le$n$ \le$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的排列,问元素相同的长度大于等于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);
    }
}
### Visual Genome 项目介绍 Visual Genome 是一个大规模的结构化数据集,旨在促进计算机视觉领域的发展[^3]。该数据集不仅提供了丰富的图像资源,还包含了详细的场景图(Scene Graph),这些图形化的表示方法能够捕捉图像中的物体、属性及其相互之间的关系。 #### 场景图构建方式 为了创建高质量的场景图,Visual Genome 使用了一种更为细致的方法——区域图。每张图片通常包含5至100个这样的局部视图,平均约为50个。通过对同一幅画作内不同部分所描绘的对象进行整合,最终形成完整的场景图。值得注意的是,并非所有的文字描述都会转化为具体的区域图;例如,“这是一个晴朗的日子”,由于缺乏具体实体而不会被纳入其中。 #### 统计特征 根据统计,在单个区域图里大约存在0.71个物体、0.52个属性以及0.43个关系;而在整个场景图层面,则分别达到了约35个物体、26个属性和21个关系的数量级。这反映了随着抽象层次升高,信息量也随之增加的趋势。 ### 应用场景概述 #### 目标检测与分类 借助于大量标记好的实例样本,研究人员可以利用此数据集训练更加精准的目标识别算法。无论是日常用品还是罕见物品都能在此找到对应的标注记录,有助于提升模型泛化能力[^2]。 #### 图像语义解析 除了简单的物体辨识外,Visual Genome 还能帮助机器更好地理解照片背后的故事。通过学习关联规则,系统可以从众多候选解释方案中挑选最合理的那一种,进而实现更高水平的认知功能。 #### 自动驾驶辅助决策 对于无人驾驶汽车而言,准确感知周围环境至关重要。基于此类详尽的地图资料库,开发者们得以开发出性能优越的道路状况监测程序,确保行车安全的同时提高效率。 ```python import torch from torchvision import models, transforms from PIL import Image def load_image(image_path): preprocess = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), ]) image = Image.open(image_path).convert('RGB') return preprocess(image).unsqueeze(0) model = models.detection.fasterrcnn_resnet50_fpn(pretrained=True) image_tensor = load_image("example.jpg") output = model(image_tensor)[0] for box, label, score in zip(output['boxes'], output['labels'], output['scores']): if score > 0.8: print(f"Detected {label.item()} with confidence {score.item()}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值