题意是定义一个好串——所有连续k长度的字串的和相等
然后你可以随意往已知串里插入随意个元素(1~n)使其成为好串,原串长度<=100,生成串长度<=1e4
感觉数据很水但是没有头绪orz
看了九峰蝶蝶的代码&IceSwords这个哥哥的博客
因为题目没有要求说是要限制字符串长度
由 n(<=100)* k( <= 100 ) <= 1e4
所以可以大胆猜想——
字符串里凡是不同元素 > k 个是一定不可以的,
然后 恰好有 k 个 比如说,k=3 串=123,那我们可以直接 1 2 3 1 2 3 1 2 3, 一个下划线一组内的乱序也可以
不足k个的时候随机补数(<=n)就ok 测试补1是可以的
所以就用set存一存字符串里有多少种元素,然后分类输出就ok
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
int n,t,k,a[10009],cnt,b[109];
int main(){
scanf("%d",&t);
while(t--){
cnt = 1;
set<int> Set;
set<int> ::iterator it;
scanf("%d %d",&n,&k);
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
Set.insert(a[i]);
}
if(Set.size() > k){ printf("-1\n");continue;}
for(it = Set.begin(); it != Set.end() ; it++){
b[cnt++] = *it;
}
printf("%d\n",n*k);
for(int i=1;i<=n;i++){
for(int j=1;j<cnt;j++)printf("%d ",b[j]);
for(int j=cnt;j<=k;j++)printf("%d ",b[cnt-1]);
}
printf("\n");
}
}