2015 Multi-University Training Contest 4(hdu5334 - Virtual Participation)数学

Virtual Participation

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 ( 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 (1≤Ai≤n) - the sequence you find.

Sample Input

10

Sample Output

4
1 2 3 4

Virtual Participation

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=100010;
const int maxm=1010;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
int K;
int len[maxn];
int main()
{
    while(scanf("%d",&K)!=EOF)
    {
        if(K<=100000)
        {
            printf("%d\n",K);
            for(int i=1;i<K;i++)
                printf("%d ",1);
            printf("1\n");
            continue;
        }
        int N=ceil((sqrt(8*(LL)K-1)-1)/2);
        int cnt=0,num=0;
        LL d=N*N+N-2*K;
        while(d)
        {
            int L=int(sqrt(1+4*d*1.0)+1)/2;
            len[++num]=L;
            cnt+=L;
            d-=(LL)L*(L-1);
        }
        printf("%d\n",N);
        for(int i=1;i<=num;i++)
        {
            for(int j=1;j<=len[i];j++)
                printf("%d ",i);
        }
        if(cnt<N)
        {
            //减掉相同的剩下的还差的不同的补全
            for(int j=1;j<=N-cnt;j++)
                printf("%d ",num+j);
        }
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值