标签:
构造
小于10^5的直接输出1
大于10^5的构造如下的串
1111...12222...233....3.....t,t+1,t+2..
设长度为n,每种字符出现了L[i]次则不同的串有 n*n+n-sigma(L[i])=2*K
大约估计一个n,用贪心求出L
Virtual Participation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 711 Accepted Submission(s): 205
Special Judge
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he asks rikka to have some practice on codeforces. Then she opens the problem B:
Given an integer K,
she needs to come up with an sequence of integers A satisfying
that the number of different continuous subsequence of A is
equal to k.
Two continuous subsequences a, b are
different if and only if one of the following conditions is satisfied:
1. The length of a is
not equal to the length of b.
2. There is at least one t that at≠bt,
where at means
the t-th
element of a and bt means
the t-th
element of b.
Unfortunately, it is too difficult for Rikka. Can you help her?
Input
There are at most 20 testcases,each testcase only contains a single integer K (1≤K≤109)
Output
For each testcase print two lines.
The first line contains one integers n (n≤min(K,105)).
The second line contains n space-separated
integer Ai (1≤Ai≤n) -
the sequence you find.
Sample Input
Sample Output
Author
XJZX
Source
Recommend
wange2014 | We have carefully selected several similar problems for you:
5342 5341 5340 5338 5337
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int LL;
const int maxn=100100;
LL K,n;
LL L[maxn];
LL bs(LL x)
{
LL low=1,high=100000;
LL ans=1;
while(low<=high)
{
LL mid=(low+high)/2;
if(mid*(mid-1)<=x)
{
ans=mid;
low=mid+1;
}
else
{
high=mid-1;
}
}
return ans;
}
void solve(LL k)
{
if(k<=100000)
{
cout<<k<<endl;
for(int i=1;i<=k;i++)
printf("%d%c",1,(i==k)?'\n':' ');
return ;
}
int nt=0;
n=1000;
while(n*n+n-2*K<=0) n+=100;
LL x=n*n+n-2*K;
while(x)
{
LL y=bs(x);
L[++nt]=y;
x-=y*(y-1);
}
printf("%d\n",(int)n);
int sum=0;
int now=0;
for(int i=1;i<=nt;i++)
{
sum+=L[i];
for(int j=0;j<L[i];j++)
{
now++;
printf("%d%c",i,(now==n)?'\n':' ');
}
}
for(int i=0;i<n-sum;i++)
{
printf("%d%c",++nt,(now==n)?'\n':' ');
}
cout<<endl;
}
int main()
{
while(cin>>K)
{
solve(K);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDOJ 5534 Virtual Participation 构造
标签:
原文地址:http://blog.csdn.net/ck_boss/article/details/47255609