Virtual Participation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 886 Accepted Submission(s): 257
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
a
t
≠b
t![]()
, where
a
t![]()
means the
t
-th element of
a
and
b
t![]()
means the
t
-th element of
b
.
Unfortunately, it is too difficult for Rikka. Can you help her?
Given an integer K
Two continuous subsequences a, b
1. The length of a
2. There is at least one t
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≤10
9
)
Output
For each testcase print two lines.
The first line contains one integers n (n≤min(K,10
5
))
.
The second line contains n
space-separated integer
A
i
(1≤A
i
≤n)
- the sequence you find.
The first line contains one integers n (n≤min(K,10
The second line contains n
Sample Input
10
Sample Output
4 1 2 3 4
Author
XJZX
Source
Recommend
假设答案只有A个1,B个2,C个3
则原题要找A+B+C<=Min(K,10^5) 且 A+B+C+AB+BC+AC=K 的解
右边方程移项得,(A+C+1)(B+C+1)=K+(1+C)^2-C
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
void work(ll k,ll &A,ll &B,ll &C)
{
A=B=C=1;
while (1)
{
int K2=k+(1+C)*(1+C)-C;
for(ll x=(ll)(sqrt(K2));x>=C+1;x--)
{
if (K2%x==0) {
A=x-C-1,B=K2/x-C-1;
if (A+B+C>100000) continue;
return;
}
}
C++;
}
}
int main()
{
// freopen("H.in","r",stdin);
ll k;
while (cin>>k) {
if (k==1) {
puts("1");
puts("1");
continue;
} else if (k==2) {
puts("2");
puts("1 1");
} else if (k<=100000){
printf("%d\n",k);
For(i,k-1) printf("1 ");printf("1\n");
} else {
ll A,B,C=0;
work(k,A,B,C);
printf("%d\n",A+B+C);
bool flag=0;
For(i,A)
{
if (!flag) flag=1;else printf(" ");
printf("1");
}
For(i,B)
{
if (!flag) flag=1;else printf(" ");
printf("2");
}
For(i,C)
{
if (!flag) flag=1;else printf(" ");
printf("3");
}printf("\n");
}
}
return 0;
}
本文针对一个具体的算法竞赛题目——虚拟参与问题进行了解析。题目要求根据给定整数K,构造一个整数序列A,使得A的不同连续子序列数量恰好为K。通过对问题的数学建模,提出了一种解决方案,并通过代码实现加以说明。

被折叠的 条评论
为什么被折叠?



