HDU 5334 Virtual Participation

博客探讨了一道脑洞题目,分析了数列中连续1和2段的情况。通过假设每段长度并简化计算,得出序列总数公式,进一步通过枚举方法解决题目限制条件。
摘要由CSDN通过智能技术生成
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

脑洞题,直接假设数列只有2个数,并且是连续的一段1,然后是连续的一段2,最后是连续的一段1

于是假设三段的长度分别为a,b,c且(a>=c)于是不同的序列总数为ab+bc+ac+a+b

然后只要让ab+bc+ac+a+b=k就好了

化简一下(a+c+1)*(b+c+1)=k+(c+1)*(c+1)

然后枚举(c+1)同时保证a>=c且a+b+c<=100000即可,貌似没有可以卡的数据

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#include<string>
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
using namespace std;
const ll maxn=100005;
int T,n,m,f[maxn];

int main()
{
    //scanf("%d",&T);
    for (int i=1;i<=33000;i++) f[i]=i*i;
    while (~scanf("%d",&n))
    {
        /*if (n<=100000)
        {
            for (int i=1;i<=n;i++)
            {
                putchar('1');
                if (i<n) putchar(' '); else putchar(10); 
            }
        }
        else */
        {
            int k,u,a,b,c,flag=0;
            for (int i=1;i<=33000;i++)
            {
                k=n+f[i];
                u=sqrt(1.0*k);
                u=min(u,k/(i+i-1));
                for (int j=u;j>=i;j--)
                if (k%j==0) 
                {
                    c=i-1;
                    b=j-i;
                    a=k/j-i;
                    if (a+b+c<=100000) flag=true;
                    if (flag) break;
                }
                if (flag) break;
            }
            printf("%d\n",a+b+c);
            flag=0;
            for (int i=1;i<=a;i++) 
            {
                if (flag) printf(" "); else flag=1;
                printf("1");
            }
            for (int i=1;i<=b;i++)
            {
                if (flag) printf(" "); else flag=1;
                printf("2");
            }
            for (int i=1;i<=c;i++) 
            {
                if (flag) printf(" "); else flag=1;
                printf("1");
            }
            putchar(10);
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值