比赛 20160923 评测结果 WEWEEEEEEE
题目名称 最长数列 最终得分 0
用户昵称 KZNS 运行时间 1.037 s
代码语言 C++ 内存使用 0.29 MiB
提交时间 2016-09-23 21:11:35
显示代码纯文本
//KZNS
#include <cstdio>
#include <algorithm>
using namespace std;
int N;
int ls[103];
void work() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", ls+i);
    sort(ls, ls+N);
    int ans = 0;
    int K, A;
    int ct;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            K = ls[j] - ls[i];
            A = ls[j];
            ct = 2;
            for (int k = j+1; k < N; k++) {
                if (A + K == ls[k]) {
                    ct++;
                    A = ls[k];
                }
                else if (A + K > ls[k]) {
                    break;
                }
            }
            ans = max(ans, ct);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (ls[j] % ls[i])
                continue;
            K = ls[j] / ls[i];
            A = ls[j];
            ct = 2;
            for (int k = j+1; k < N; k++) {
                if ((long long)A * K == ls[k]) {
                    ct++;
                    A = ls[k];
                }
                else if ((long long)A * K > ls[k]) {
                    break;
                }
            }
            ans = max(ans, ct);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (ls[j] % ls[i])
                continue;
            K = ls[j] / ls[i];
            A = ls[j];
            ct = 2;
            for (int k = j+1; k < N; k++) {
                if (A * K == ls[k]) {
                    ct++;
                    A = ls[k];
                }
                else if (A * K > ls[k]) {
                    break;
                }
            }
            ans = max(ans, ct);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++)
            if (ls[j] == ls[i])
                ct++;
        ans = max(ans, ct);
    }
    ct = 0;
    bool fff = false;
    for (int i = 0; i < N; i++) {
        if (ls[i] == 1)
            ct++;
        else if (ls[i])
            fff = true;
    }
    if (fff)
        ct++;
    ans = max(ans, ct);
    printf("%d\n", ans);
}
int main() {
    freopen("series.in", "r", stdin);
    freopen("series.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while (T--) {
        work();
    }
    return 0;
}
//UBWH