40pts求助
查看原帖
40pts求助
1192648
LHX_18460366315楼主2024/11/10 21:48

我的思路:打表+数学规律,CCF和洛谷都是40分(悲)

#include<bits/stdc++.h>
using namespace std;

int a[10] = {0,2,5,5,4,5,6,3,7,6};
int ans[105] = {0,1,7,4,2,6,8,10,18,22,
           20,28,68,88,108,188,200,208,288,688,
           888};

int main(){
    freopen("sticks.in","r",stdin);
    freopen("sticks.out","w",stdout);
    long long t,n;
    scanf("%lld",&t);
    for (int i = 1;i <= t;i++){
        scanf("%lld",&n);
        if (n < 2){
            printf("-1\n");
        }else if ((n - 1) <= 20){
            printf("%d",ans[n - 1]);
            printf("\n");
        }else {
            long long m = floor(n / 7) - 2;
            printf("%d",ans[14 + (n - 1) % 7]);
            for (int j = 1;j <= m;j++){
                printf("8");
            }
            printf("\n");
        }
    }
    return 0;
}
2024/11/10 21:48
加载中...