标签:
简单构造,设数列为1,1,...,1,2,2,...,2,3,3,....,3
设有 x 个1,y 个 2, z 个 3,枚举x,y即可。
不同的连续子序列有x + y + z + x*y + y*z + x*z。。。。
因为事实上K<=10^9时,最小的合法的 x 也不超过100.。。
所以复杂度远远没有想象中那么高。。。。。
10
4 1 2 3 4
#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
const int N = 100000;
int main()
{
int K;
while (scanf("%d", &K)==1) {
if (K<=2)
{
if (K==1) puts("1\n1");
if (K==2) puts("2\n1 1");
continue;
}
bool f = 1;
for (int x=0;f && x<=1e5;x++) {
for (int y=0;x+y<=1e5&&x+y+x*y<=K&&y<=sqrt(K+0.5);y++)
{
int t = K - x - y - x * y;
if (t % (x+y+1)==0) {
int z = t / (x + y + 1);
if (z < 0 || x+y+z>min(N, K)) continue;
assert(x+y+z+x*y+y*z+x*z==K);
int n = x + y + z;
printf("%d\n", n);
for (int i=1;i<=n;i++) {
int c;
if (i<=x) c=1;
else {
if (i<=x+y) c = 2;
else c = 3;
}
printf("%d%c", c, i==n ? 10 : ' ' );
}
f =false;
break;
}
}
}
assert(!f);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5334 Virtual Participation
标签:
原文地址:http://blog.csdn.net/oilover/article/details/47164727