HDU 4691 正解后缀数组(暴力也能过)

本来是个后缀数组,考察算法的中级题目,暴力居然也可以水过,就看你跳不跳坑了(c++和G++返回结果就很不一样,关键看编译器)

HDU 4691 正解后缀数组(暴力也能过)

丝毫不差的代码,就看运气如何了。唯一差别c++还是G++,但正解是后缀数组没错,趁机学一下吧。

 #include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(ll i = a; i < b; i++)
#define repd(i, a, b) for(ll i = b; i >= a; i--)
#define sfi(n) scanf("%I64d", &n)
#define MAXN 100010
#define N 100010
ll n,num1;
char s[MAXN];
ll a[N],b[N];
ll solve()
{
ll num = num1;
repu(i,,n)
{
ll st1 = a[i],st2 = a[i-];
int t = ;
while(s[st1] == s[st2]&& st1 < b[i] && st2 < b[i-])
{
t++;
st1++;
st2++;
}
if(t == )
num += ;
else
num += (int)log10(t) + ;
num += ;
num -= t;
}
return num + ;
}
int main()
{
while(~scanf("%s",s))
{
scanf("%I64d",&n);
num1 = ;
repu(i,,n)
{
scanf("%I64d%I64d",&a[i],&b[i]);
num1 += (b[i] - a[i]);
}
num1 += n;
ll num2 = solve();
printf("%I64d %I64d\n",num1,num2);
}
return ;
}

暴力水过代码

后缀数组待学习:

上一篇:【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)


下一篇:fzu 2171 防守阵地 II