hdu5334(2015多校4)--Virtual Participation(构造)

题目链接:点击打开链接

题目大意:给出一个数字k,要求做出一个长度小于等于10^5的序列,该序列中不相同的连续子序列有k个。

构造啊,,,,,,一点辙都没有

使用连续的数字做成序列,可以省事的计算出不相同的子序列有多少个。

使用n个1,那么不相同子序列有n种。

使用n个1和m个2,那么不相同的子序列有n+m+n*m种。

使用n个1,m个2和l个3,那么不相同的子序列有n+m+l+n*m+n*l+m*l种。

当k小于等于10^5时,直接输出k个1。

当k大于10^5时,对于使用1,2,3的情况可以做出满足各种k的子序列。

那么我们要求的就是求出n,m,l的值,

令a = n+l+1 , b = m+l+1 , c = l ; 得到a,b是为了凑出n+m+l+n*m+n*l+m*l,最终a*b = k + c*c + c + 1

枚举c,求k+c*c+c+1的所有约数,看是否有a和b满足a = n+l+1 , b = m+l+1 , c = l 并且n+m+l <= 10^5

如果存在了就输出连续的n个1,m个2,l个3.

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define LL __int64
int main() {
    LL k , a , b , c ;
    LL i , j , l , flag ;
    while( scanf("%I64d", &k) != EOF ) {
        if( k <= 100000 ) {
            printf("%I64d\n", k) ;
            for(i = 1 ; i < k ; i++)
                printf("1 ") ;
            printf("1\n") ;
            continue ;
        }
        l = flag = 0 ;
        while( 1 ) {
            c = k+l*l+l+1 ;
            for(j = l+1 ; j*j <= c ; j++) {
                a = j ;
                if( c%a ) continue ;
                b = c/a ;
                if( b < l+1 ) continue ;
                if( a-l-1+b-l-1+l <= 100000 ) {
                    flag = 1 ;
                    break ;
                }
            }
            if( flag ) break ;
            l++ ;
        }
        printf("%I64d\n", a+b-l-2) ;
        for(i = 0 ; i < a+b-l-2 ; i++) {
            if( i < a-l-1 )
                printf("1") ;
            else if( i < a+b-2*l-2 )
                printf("2") ;
            else
                printf("3") ;
            if( i == a+b-l-3 ) printf("\n") ;
            else printf(" ") ;
        }
    }
    return  0 ;
}

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

时间: 2024-08-24 16:27:01

hdu5334(2015多校4)--Virtual Participation(构造)的相关文章

HDOJ 5534 Virtual Participation 构造

构造 小于10^5的直接输出1 大于10^5的构造如下的串 1111...12222...233....3.....t,t+1,t+2.. 设长度为n,每种字符出现了L[i]次则不同的串有  n*n+n-sigma(L[i])=2*K 大约估计一个n,用贪心求出L Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi

hdu5301(2015多校2)--Buildings(构造)

Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 472    Accepted Submission(s): 104 Problem Description Your current task is to make a ground plan for a residential building located

解题报告 之 HDU5334 Virtual Participation

解题报告 之 HDU5334 Virtual Participation 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 , she needs to come up wit

2015多校.MZL&#39;s endless loop(欧拉回路的机智应用 || 构造)

MZL's endless loop Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 898    Accepted Submission(s): 178Special Judge Problem Description As we all kown, MZL hates the endless loop deeply, and he

HDU 5334 Virtual Participation

简单构造,设数列为1,1,...,1,2,2,...,2,3,3,....,3 设有 x 个1,y 个 2, z 个 3,枚举x,y即可. 不同的连续子序列有x + y + z + x*y + y*z + x*z.... 因为事实上K<=10^9时,最小的合法的 x 也不超过100... 所以复杂度远远没有想象中那么高..... Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to