解题报告 之 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 with an sequence of integers  satisfying
that the number of different continuous subsequence of  is
equal to .

Two continuous subsequences  are
different if and only if one of the following conditions is satisfied:

1. The length of  is
not equal to the length of .

2. There is at least one  that ,
where  means
the -th
element of  and  means
the -th
element of .

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 

Output

For each testcase print two lines.

The first line contains one integers .

The second line contains  space-separated
integer  -
the sequence you find.

Sample Input

10 

Sample Output

4
1 2 3 4 

题目大意:要求你构造一个数字序列,这个序列中不相同的连续子序列数为K。这些连续子序列不相同要么长度不同,或者长度相同但存在一个位置的数字不相同。输出找到的序列有多少个数构成,再输出这些数。(要求构造的序列长度不超过1e5)

分析:一开始没什么思路,后来看了题解才知道的。首先明确,如果这个序列由一种数构成(如仅由1构成),长度为a。那么子序列数量为a个;如果由1111122222……构成,其中1长度为a,2长度为b,那么子序列数量为a+b+a*b(选几个1选几个2);如果由11111222223333……构成,那么子序列数量为a+b+c+a*b+b*c+a*c,分别对应只选1,只选2,只选3,选几个1几个2,选几个2几个3,选几个1而2全选再选几个3。

第一种情况,K<=1e5,那么直接输出K个1即可。

第二种情况,K>1e5,用1、2、3可以构造(这里我也不知道为什么?求大神解答)。那么假设有a个1,b个2,c个3。

那么就是要求a+b+c+a*b+b*c+a*c=K的解。化简一下得到(a+c+1)*(b+c+1)=
K+c^2+c+1;

然后枚举c,K为已知数,然后枚举右边的约数(这也是化简的原因),看满不满足(a+c+1)、(b+c+1)都合法。如果找到合法,就反解出abc然后输出完事。

另附官方做法,更加是看不懂,数学渣渣表示跪了。(http://blog.csdn.net/u010660276/article/details/47188023

上代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>

using namespace std;
typedef long long ll;

int main()
{
	ll k;
	while(cin >> k)
	{
		if(k <= 1e5)
		{
			cout <<k << endl;
			for(int i = 1; i <= k; i++)
			{
				printf( "1" );
				if(i == k) printf( "\n" );
				else printf( " " );
			}
			continue;
		}
		ll a, b, c=0;
		int flag = 0;
		while(1)
		{
			ll s = k + c*c + c + 1;
			for(int i = c + 1; i*i <= s; i++)
			{
				a = i;
				if(s%a != 0)continue;
				b = s / a;
				if(b < c + 1)continue;

				if(a + b - c - 2 <= 1e5)
				{
					flag = 1;
					break;
				}
			}
			if(flag) break;
			else c++;
		}

		cout << a + b - c - 2 << endl;
		for(int i = 1; i <= a - c - 1; i++)
			printf( "1 " );
		for(int i = 1; i < b - c - 1; i++)
			printf( "2 " );
		if(c == 0) printf( "2\n" );
		else
		{
			printf( "2 " );
			for(int i = 1; i < c; i++)
				printf( "3 " );
			printf( "3\n" );
		}
	}
	return 0;
}

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

时间: 2024-08-26 15:34:00

解题报告 之 HDU5334 Virtual Participation的相关文章

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值就会减一

08年acm区域赛北京赛区 部分题解题报告

08年区域赛北京赛区 http://poj.org/searchproblem?field=source&key=Beijing+2008 POJ 3921 Destroying the bus stations 题目还是比较难的,当时的榜似乎只有4/25的通过/提交,其实题目数据很水.学长转换模型写了网络流求最小割,可以AC,不过自己造了个数据推翻了正确性.我写了个很挫的bfs套bfs,外层是最小的删除点数,内层是求最短路,数据很水可以AC.但比较蛋疼的在于bfs耗内存,而且队列中的点数是阶乘

解题报告 之 POJ3057 Evacuation

解题报告 之 POJ3057 Evacuation Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

【百度之星2014~初赛(第二轮)解题报告】Chess

声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站,因此,笔者添加此条声明. 郑重声明:这篇记录<[百度之星2014~初赛(第二轮)解题报告]Chess>转载自 http://tiankonguse.com/ 的这条记录:http://tiankonguse.com/record/record.php?id=667 前言 最近要毕业了,有半年没做

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh童鞋的提醒. 勘误2:第7题在推断连通的时候条件写错了,后两个if条件中是应该是<=12 落了一个等于号.正确答案应为116. 1.煤球数目 有一堆煤球.堆成三角棱锥形.详细: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形). -. 假设一共

[noip2011]铺地毯(carpet)解题报告

最近在写noip2011的题,备战noip,先给自己加个油! 下面是noip2011的试题和自己的解题报告,希望对大家有帮助,题目1如下 1.铺地毯(carpet.cpp/c/pas) [问题描述]为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有n 张地毯,编号从1 到n.现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上.地毯铺设完成后,组织者想知道覆盖地面某个点的最上面的那张地毯的

ACdream 1203 - KIDx&#39;s Triangle(解题报告)

KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description One day, KIDx solved a math problem for middle students in seconds! And than he created this problem. N

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.