不知道是哪一年的腾讯马拉松题目 照片评级 解题报告
第一题大水,懒得写。
第二题伤了很久的脑筋,想出了一个算法结果ultramanhu基于此想出了个更容易理解更容易实现的方法。
#include <cstdio>
#include <iostream>
typedef int LISTYPE;
#define LISMAXN 100005
LISTYPE lR[LISMAXN];
int LIScmp(int a, int b, LISTYPE list[])
{
return list[a] + b - a <= list[b];
}
int LISLength(LISTYPE list[], int n)
{
int length = 1;
lR[0] = 0;
for (int i = 1; i < n; i++)
{
//二分查找,复杂度 log(n)
int b, e, m;
b = 0;
e = length - 1;
while (b <= e && e >= 0)
{
m = (b + e) / 2;
if (LIScmp(lR[m], i, list))
b = m + 1;
else
e = m - 1;
}
if (0 == b)
continue;
lR[b] = i;
if (b >= length)
length++;
}
return length;
}
LISTYPE LOri[LISMAXN];
int main() {
int n;
scanf("%d", &n);
while (n-- > 0){
int size;
scanf("%d", &size);
LOri[0] = 0;
for (int i = 1; i <= size; ++i){
scanf("%d", &LOri[i]);
}
printf("%d\n", size + 1 - LISLength(LOri, size + 1));
}
return 0;
}Last updated
Was this helpful?