码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-20 20:54:45      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:


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?
 

Input
There are at most 20 testcases,each testcase only contains a single integerK (1K10技术分享9技术分享)技术分享
 

Output
For each testcase print two lines.

The first line contains one integers n (nmin(K,10技术分享5技术分享))技术分享.

The second line contains n技术分享 space-separated integer A技术分享i技术分享 (1A技术分享i技术分享n)技术分享 - 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;
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

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

标签:

原文地址:http://blog.csdn.net/nike0good/article/details/47813717

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!