摘要:
直接暴力的话,O(n2),肯定会超时。分解到两个轴上,通过递推求解,O(nlgn)。要理解这种高效求距离的方法。数轴上的某一点到其他点的距离,可通过从小到大或从大到小递推来做。#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll _int64
using namespace std;
const int maxn=100010;
int x[maxn],y[maxn],rx[maxn],ry[maxn];
ll disx[maxn],disy[maxn];
int n;
l 阅读全文
posted @ 2012-12-27 16:05
LJ_COME!!!!!
阅读(128)
评论(0)
推荐(0)
摘要:
字符串匹配。kmp.#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int maxn=100010;
char tran[26],s[maxn];
int next[maxn];
void getv(char * t)//求失配函数
{ int i,j;strlen int m=(t); next[0]=-1; i=0;j=-1; while(i<m-1) { if(j==-1||t[i]==t[j]) { j++;i++; if 阅读全文
posted @ 2012-12-27 09:34
LJ_COME!!!!!
阅读(110)
评论(0)
推荐(0)

浙公网安备 33010602011771号