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 Submission(s): 711    Accepted Submission(s): 205

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 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 (1≤K≤109)

Output

For each testcase print two lines.

The first line contains one integers n (n≤min(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

Author

XJZX

Source

2015 Multi-University Training Contest 4

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5342 5341 5340 5338 5337

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long int LL;

const int maxn=100100;

LL K,n;
LL L[maxn];

LL bs(LL x)
{
	LL low=1,high=100000;
	LL ans=1;
	while(low<=high)
	{
		LL mid=(low+high)/2;
		if(mid*(mid-1)<=x)
		{
			ans=mid;
			low=mid+1;
		}
		else
		{
			high=mid-1;
		}
	}
	return ans;
}

void solve(LL k)
{
    if(k<=100000)
    {
		cout<<k<<endl;
        for(int i=1;i<=k;i++)
            printf("%d%c",1,(i==k)?'\n':' ');
        return ;
    }
	int nt=0;
	n=1000;
	while(n*n+n-2*K<=0) n+=100;
	LL x=n*n+n-2*K;

	while(x)
	{
		LL y=bs(x);
		L[++nt]=y;
		x-=y*(y-1);
	}

	printf("%d\n",(int)n);
	int sum=0;
	int now=0;
	for(int i=1;i<=nt;i++)
	{
		sum+=L[i];
		for(int j=0;j<L[i];j++)
		{
			now++;
			printf("%d%c",i,(now==n)?'\n':' ');
		}
	}
	for(int i=0;i<n-sum;i++)
	{
		printf("%d%c",++nt,(now==n)?'\n':' ');
	}
	cout<<endl;
}

int main()
{
    while(cin>>K)
    {
        solve(K);
    }
    return 0;
}

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

时间: 2024-08-10 21:52:00

HDOJ 5534 Virtual Participation 构造的相关文章

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/

解题报告 之 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

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的情况可以

HDOJ 4671 Backup Plan 构造优先队列

优先队列构造前两列.... Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 775    Accepted Submission(s): 365 Special Judge Problem Description Makomuno has N servers and M databases. All databa

hdu5334 Virtual Participation 多校联合第四场

题意:给你一个数k,让你输出一个长度为n的数列, 该数列满足 不相等的子序列的个数和为k 关于不相等的定义题中有给出 思路:规律题  当k小于十万时,直接输出k个1,如果题目不要求n的范围 这道题可以都是输出k个1..... 当k大于十万时首先对于一个1到n的数列 它对应的k值为n*(n+1)/2,然后打表 打到45000 就够了,然后再判断表中离k最近切大于k的数是多少,假设为n,我们想办法使其减去n即可办法如下:对于一个1到n的数列,如果我们将其某个数变为1(不与1相邻) 那么其k值就会减一

HDOJ 5385 The path 构造

The path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 190 Special Judge Problem Description You have a connected directed graph.Let d(x) be the length of the s

HDU 5334 Virtual Participation(2015多校第四场)

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 

AtCoder AGC #3 Virtual Participation

Havana真好听qwq AB题就不写了 SB C.BBuBBBlesort! 有一个长度为$n$的数列 你每次可以用两种操作 1.交换两个相邻元素 2.交换两个隔且仅隔了一个的元素 求把数列排成有序的,最少需要多少1操作 sol:显然,2操作并不会改变排序后元素所处位置的奇偶性 我们找到所有排序后位置与现在位置差为奇数的点,再除以2就可以了 D.Anticube 给出$n$个两两不同的数,选出一些数使得不存在两个数的积是完全立方数,求能选出的最大数量 sol:套路 把每个数分解质因数,求出他们

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

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 ab