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

来源:互联网 发布:js 日期转时间戳 编辑:程序博客网 时间:2024/04/30 10:00


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 integerK (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
41 2 3 4
 

Author
XJZX
 

Source
2015 Multi-University Training Contest 4
 

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
原创粉丝点击