HDU 5334(Virtual Participation-(A+C+1)(B+C+1)=K+(1+C)^2-C)


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 atbt , 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 (1K109)
 

Output
For each testcase print two lines.

The first line contains one integers n (nmin(K,105)) .

The second line contains n space-separated integer Ai (1Ain) - the sequence you find.
 

Sample Input
  
  
10
 

Sample Output
  
  
4 1 2 3 4
 

Author
XJZX
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5416  5415  5414  5413  5412 
 







假设答案只有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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值