Codeforces 1059C

部署运行你感兴趣的模型镜像

题意:给定一个数n,表示1,2,3,4,5,6......n的序列。执行如下几个操作:求序列的最大公因数,删除序列中的任意一个数,再求最大公因数,一直执行下去,直至序列为空,让输出序列构成的字典序列最大。

题解:有点贪心的思想在里面。①、最开始的n个数的序列的GCD=1。②、相邻的两个数互质,为了使得每一步的GCD最大,需要消灭相邻的数字。故第一步就是删除1,不然GCD会一直为1。此外,可以这么想:n个数中偶数的个数大体上占了一半,而这些偶数至少有一个公因数2,所以接下来我们要删除所有的奇数,想想这是为什么呢?(就算为了消除相邻数而把偶数消除,剩余的奇数的GCD也还有可能为1,这么做有点亏)。删除所有的奇数以后剩下 : 2 4 6 8 10 12 14 16......接下来该怎么做呢

GCD(2,4,6,8,10,12,14...)=2*GCD(1,2,3,4,5,6,7....),就和之前的一样了,1 2 3 4 5 6 7....GCD增大的方法和之前一样哈,还是先去除奇数。剩下4 8 12 16....留下的至少都是4的倍数。GCD(4,8,12,16....)=4*GCD(1 2 3 4 5 6)一样哈,留下的变成8 16 24...都是8的倍数了。

最后我们来讨论一个特殊的情况,当经过一系列操作剩下3个数怎么办?假设这三个是 GCD ,2*GCD,3*GCD。我们仿照前面的做法是删去GCD和3*GCD么,当然不是啦,这时候要删去GCD,2*GCD(动手模拟一下就知道了)。

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int gcd = 1;
	while(n)
	{
		if(n==3)
		{
			printf("%d %d %d\n",gcd,gcd,3*gcd);
			return 0;
		}
		for(int i=1;i<=n/2+n%2;i++) printf("%d ",gcd);	
		gcd*=2;
		n/=2;	
	}
	return 0;
}                     

 

 

您可能感兴趣的与本文相关的镜像

Kotaemon

Kotaemon

AI应用

Kotaemon 是由Cinnamon 开发的开源项目,是一个RAG UI页面,主要面向DocQA的终端用户和构建自己RAG pipeline

### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值