hdu 5334 Virtual Participation 构造

Virtual Participation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 639    Accepted Submission(s): 180
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

题意:

给一个k,求出一个长度小于10^5的序列,该序列的不同子串的个数为k

分析:


求出第一个满足 n*(n+1)/2 >= k 的数字

然后对于F = n*(n+1)/2 - k,求出一些数,满足x1*(x1-1)+x2*(x2-1) ...... = F

第二个函数是有解的。bestcoder上有一题的题解说,任意数字,最少可以由3个三角数构成。





#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
int main(){
    ll k;
    while(scanf("%I64d",&k)!=EOF){
        if(k <= 100){
            printf("%I64d\n",k);
            for(int i = 0;i < k; i++){
                if(i == 0)printf("1");
                else printf(" 1");
            }
            printf("\n");
            continue;
        }
        vector<ll> head;
        ll n = 0;
        for(n = 0;;n++){
            if(n*(n+1)/2>=k) break;
        }
        ll su = n*(n+1)-2*k;
        while(su > 0){
            ll x = 0;
            for(x=0;;x++){
                if(x*(x+1) > su ) break;
            }
            head.push_back(x);
            su -= x*(x-1);
        }
        printf("%I64d\n",n);
        int flag = 0,cnt = 1,L=0;
        for(int i = 0;i < head.size(); i++){
            for(int j= 0;j < head[i]; j++){
                if(flag) printf(" ");
                printf("%d",cnt);
                flag = 1;
            }
            L+=head[i];
            cnt++;
        }
        while(L<n){
            if(flag) printf(" ");
            printf("%d",cnt);
            cnt++;
            L++;
        }
        printf("\n");
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值