题目链接:uva 1392 - DNA Regions
题目大意:给n和p,以及两个DNA序列,要求找出其中突变率不超过p%的最长子串的长度。
解题思路:s[i]表示前i个有s[i]个突变,这样的话就有s[j] - s[i]/(j - i) ≤ p * 100,即有s[j] *100 - p * j ≤ s[i] * 100 - p * i为区间[i,j]是否符合突变率小于p%;也就是说对于每个位置,找到一个最小的x,满足s[x] * 100 - p * x ≥ s[i] * 100 - p * i,长度i-x即为i往前的最优解。所以只要维护一个递减序列,然后二分即可。
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 150005;
const int INF = 0x3f3f3f3f;
struct state {
int sum, id, key;
}s[N], c[N];
int n, p, ans, cnt;
char a[N], b[N];
int find (int key) {
int l = 0, r = cnt - 1;
while (l < r) {
int mid = (l + r) / 2;
if (c[mid].key <= key) r = mid;
else l = mid+1;
}
return c[l].id;
}
bool solve () {
ans = 0;
cnt = 1;
s[0].sum = s[0].id = 0; s[0].key = 0;
c[0] = s[0];
for (int i = 1; i <= n; i++) {
s[i].sum = s[i-1].sum + (a[i-1] != b[i-1]);
s[i].id = i; s[i].key = i * p - 100 * s[i].sum;
if (s[i].key < c[cnt-1].key) {
c[cnt++] = s[i];
} else {
int t = find(s[i].key);
ans = max(ans, s[i].id - t);
}
}
if (ans) return true;
return false;
}
int main () {
while (scanf("%d%d", &n, &p) == 2 && n + p) {
scanf("%s%s", a, b);
if (solve()) printf("%d\n", ans);
else printf("No solution.\n");
}
return 0;
}
分享到:
相关推荐
将能量感知视频编码和感兴趣区视频编码两种技术有机结合
资源分类:Python库 所属语言:Python 资源全名:django-indonesia-regions-1.0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:django-indonesia-regions-1.0.0rc1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
cyclone-regions ,垃圾回收,大家理解一下
曲线插补文章
Laravel开发-regions 蜂窝区域列表
Characterization of Quasi-Stationarity Regions for Vehicle-to-Vehicle Radio Channels
Shared memory regions——Berkeley db共享内存区域介绍
多区域可伸缩视频编码方法,李策,薛建儒,人类视觉系统对视觉的感知具有非均匀性,特别是在运动视频中人们关注的往往仅是个别的运动目标,而非全部场景。同时,视频传输中
R-CNN, matlab 代码: Regions with Convolutional Neural Network Features,卷积神经网络,此代码容易看懂,实现,适合学习 改进!
HRNet-High-Resolution Representations for Labeling Pixels and Regions.pdf
安装pip install django-world-regions 将world_regions添加到INSTALLED_APPS python manage.py migrate用法from world_regions.models import Regionregion = Region.objects.get(countries__country='US')print ...
Based on the self-organizing modeling principle in the dissipative structure theory, the paper regards the migration coupling between the regions as the influence factor to create the model of ...
usage: billow-list [-h] [-a] [-r REGION] [--regions [REGIONS [REGIONS ...]]] [-j | -y] billow list optional arguments: -h, --help show this help message and exit -a, --auto auto-detect (default: ...
求取Multi-Dimensional Maximally Stable Extremal Regions,下载于美国加利福尼亚大学洛杉矶分校
布里斯科-nf-托比亚斯 Joaquinas的分析管道与Tobias分析工具一起使用 管道轮廓 管道运行的不同步骤。... --regions regions.bed \ --peaks regions.bed \ --blacklist blacklist.bed \ --motifs mo
主要介绍多中心区域中的相关概念,原理,测度方法,英文版本(需要请注意)!
在开发z-wave 或者需求产品的时候必须知道每个国家的频率
梯度幅值图像矩阵代码极端水平(EREL)检测器的极端区域 作者:,,, 以下存储库包含EREL检测器的原始实现。 贡献。 EREL的主要贡献是: 引入了一个新的兴趣点,称为梯度幅度的最大值(MGM) 。...
最全最新中国省,市,地区json及sql数据 ,