hdu5902 GCD is Funny

Win10本地账户密码遗忘?巧用指纹/PIN快速重置(家庭版/专业版通用指南) 本文提供了一份详细的Win10本地账户密码遗忘自救指南,适用于家庭版和专业版用户。核心方法是利用已登录的指纹或PIN码权限,通过创建新的管理员账户或使用系统工具,安全重置遗忘的本地账户密码,无需第三方工具或重装系统,有效保护个人数据。 阅读详情

GCD is Funny

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 354    Accepted Submission(s): 83


Problem Description
Alex has invented a new game for fun. There are n integers at a board and he performs the following moves repeatedly:

1. He chooses three numbers a, b and c written at the board and erases them.
2. He chooses two numbers from the triple a, b and c and calculates their greatest common divisor, getting the number d (d maybe gcd(a,b), gcd(a,c) or gcd(b,c)).
3. He writes the number d to the board two times.

It can be seen that after performing the move n−2 times, there will be only two numbers with the same value left on the board. Alex wants to know which numbers can left on the board possibly. Can you help him?
 

Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤100), indicating the number of test cases. For each test case:

The first line contains an integer n (3≤n≤500) -- the number of integers written on the board. The next line contains n integers: a1,a2,...,an (1≤ai≤1000)-- the numbers on the board.
 

Output
For each test case, output the numbers which can left on the board in increasing order.
 

Sample Input
3 4 1 2 3 4 4 2 2 2 2 5 5 6 2 3 4
 

Sample Output
1 2 2 1 2 3
 


BC这一场这道题真是惨烈……MyRoom只有一人过的……什么时候BC第一题这么难过了……

本来是想直接两两GCD去重输出,因为当时想的是a, b, c, e, f

取a, b, c,那么gcd(a, b) = d,丢掉c,最后得到d, d, e, f,然后再取

d, d, e,那么gcd(d, d) = d,丢掉e,最后得到d, d, f,然后再gcd(d, d) = d,

丢掉f,最后得到d, d

也就是说任选两对都可以最后得到这两对的gcd作为最后结果,数据太水,pretest过了就没多想


后来仔细想想,谁跟你说d, d, e的时候一定选gcd(d, d) = d丢掉e的……也可能gcd(d, e) = x,丢掉d啊……这样结果就可能变成3个数,4个数或者更多个数的GCD了


这样的话也就是说在我原来的想法中,每一次求gcd都有可能做一次gcd(d, e) = x,从而变成多一个数的gcd,也就是说最后的答案应该是序列中任选i个数的gcd(2 <= i <= n - 1),因为第一次操作无论如何都会直接丢弃一个数,所以最多只能求出来n - 1个数的GCD


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

using namespace std;

const int maxn = 500;
int T, n, a[maxn + 5];
bool g[1000 + 5]; //用来标记某gcd是否之前出现过,用于去重

int gcd(int m, int n) {
	if (!n) return m;
	return gcd(n, m % n);
}

int main()
{
	cin >> T;
	while (T--) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		memset(g, false, sizeof(g));
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				g[gcd(a[i], a[j])] = true;
			}
		}
		bool flag = true;
		//需要跑n - 3次,因为第一步的操作相当于去掉了3个元素,然后把gcd的初始信息存储在g中了
		//不能多也不能少,多了的话就有可能计算出n个数的gcd了,但最多只能是n - 1个的,因为无论如何第一步操作会直接丢弃一个数
		int cnt = 1;
		while (flag && cnt <= n - 3) {
			cnt++;
			flag = false;
			for (int i = 1; i <= 1000; i++) {
				if (g[i]) {
					for (int j = 0; j < n; j++) {
						if (!g[gcd(a[j], i)]) {
							flag = true;
							g[gcd(a[j], i)] = true;
						}
					}
				}
			}
		}
		bool first = true;
		for (int i = 1; i <= 1000; i++) {
			if (g[i]) {
				if (first) {
					printf("%d", i);
					first = false;
				}
				else {
					printf(" %d", i);
				}
			}
		}
		puts("");
	}
	return 0;
}



SMPLify-x-master | 复现记录 由于毕业设计中将会用到smpl模型,而smplify方法的各环境依赖版本比较老,复现不太容易,因此便进行了smplifyx方法使用smplx的方法。由于在过程中遇到较多坑,因此进行记录和分享。 阅读详情

相关推荐

ADB命令解锁Android手机屏幕的3种实用方法(附详细步骤)

本文详细介绍了在Android手机屏幕失灵或密码遗忘时,利用ADB命令解锁屏幕的三种实用方法。包括通过ADB模拟输入事件、移除锁屏认证文件(需Root权限)以及结合恢复模式抢救数据。文章提供了详细的操作步骤与风险提示,强调提前开启USB调试的重要性,是Android用户应对紧急锁屏情况的有效技术指南。

weixin_29229055的博客 955

hdu 5902 GCD is Funny

Problem Description Alex has invented a new game for fun. There arenintegers at a board and he performs the following moves repeatedly:1. He chooses three numbersa,bandcwritten at the boa...

awow80285的博客 168

从末流211到东南软院:一个普通CS学生的保研逆袭全记录(含GPA、竞赛、面试避坑点)

本文详细记录了一位来自末流211院校的CS学生如何通过合理规划和持续努力,成功保研东南大学软件学院的完整历程。文章分享了GPA提升、竞赛策略、夏令营申请和预推免准备等关键环节的实战经验,特别强调了竞赛在弥补科研短板中的重要作用,为普通背景学生提供了可复制的保研逆袭方案。

weixin_33417488的博客 399

HDU5902

问题描述 Alex发明了一个有趣的游戏. 一开始他在黑板上写了nn个正整数, 然后他开始重复进行如下的操作: 他选择黑板上三个数字aa, bb和cc, 把他们从黑板上擦掉. 他从这三个数aa, bb和cc中选择了两个数, 并计算出他们的最大公约数, 记这个数为dd (dd 可以是\gcd(a,b)gcd(a,b), \gcd(a,c)gcd(a,c)或者\gcd(b, c)gcd(b,c)). 他

NineFailure的博客 546

Linux 隐藏进程

这种方式属于DKoM(Direct Kernel Object Manipulation)攻击方式了,即直接内核对象操作技术。关于第一种hook方式可以参考上一篇文章。最后推荐一个rootkit工具。

chi's blog 2063

Unity雷达图效果实现

unity雷达图源码

a604263644的博客 1033

HDU-5902-GCD is Funny解题笔记

Alex has invented a new game for fun. There arenintegers at a board and he performs the following moves repeatedly:1. He chooses three numbersa,bandcwritten at the board and erases them....

darren0424的博客 245

从原理到落地:Mamba-YOLOv8 全面实战指南(源码 + 训练 + 部署一次学会)

在目标检测领域,CNN与Transformer的较量从未停歇。本文提出一种革命性的架构——,将状态空间模型(SSM)首次引入YOLO框架。实验表明,该模型在COCO数据集上达到54.3% mAP@0.5,推理速度达89 FPS(RTX 4090),相比原版YOLOv8提升12.7%精度与23%速度。本文将完整揭示其技术原理与工程实现,助您掌握这一前沿技术。

FJN110的博客 127

HDU - 5902 GCD is Funny 数论(GCD相关)

思路: 首先这个题我们可能想到的就是任意两个数的 gcd , 但是这样还不够,可能会有 已经得出的gcd 跟其他的数产生新的 gcd,所以,这个题的答案就是 n 个数所有子集的gcd (上面这些想了好久没能证明== 感谢Q巨 tls 九哥 等大神 瞬间给出我没想出来的反例,当头一棒,叫我清醒,对数学更加喜欢) #include #include #include #include

床前明月光 396

labview高低拼接的理解

计算机的一个字节由8位组成,无符号的8位整形表示的范围为0~255,范围太小了,所以用双字节,即16位整形表示更大范围的数字0 ~65535。2.labview中的高低拼接实质是高8位字节左移8位与低8位字节相加,结果是双字节整形。

qwerqwerdhr的博客 848

Qt入门教程【环境搭建篇】Qt6+Mingw+QMake+QtCreator

Qt Windows平台安装

小鱼酱的博客 2万+

Hdu-5902-GCD is Funny (gcd)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5902题目大意: 给定n个数,每次操作可以取其中3个,选择其中两个作gcd运算,并向原串中添加两次gcd结果,即a,b,c三个数,可取a,b作gcd(a,b)=g,将g写入原序列两次,求进行n-2次操作后,留下的数可能是什么分析: 每次操作,取三个数,放回两个数,同时放回的数必定是原序列中数两两g

SD_Stjean的博客 401

基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的远距离停车位检测系统(深度学习代码+UI界面+训练数据集)

本文详细介绍了基于YOLOv5/YOLOv6/YOLOv7/YOLOv8深度学习模型的远距离停车位检测系统的完整实现方案。该系统能够准确识别200米范围内的停车位状态,为智能停车场管理系统、自动驾驶车辆提供关键的视觉感知能力。文章涵盖算法原理、数据集构建、模型训练、系统实现及优化策略,并提供完整的代码实现和UI界面设计。关键词:YOLO系列,深度学习,停车位检测,计算机视觉,智能交通系统pythonimport cv2import os"""创建数据存储目录""""""定时采集图像"""

YOLO 189

HDU-5902-GCD is Funny

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5902 题意:给出数组a[],从中取出3个数,放回其中任意两个数的GCD 两次,直到最后剩下两个数字,问最后剩下的数字可能有什么。 题解: 跑n-2轮两两GCD,不断更新gcd数组直到无新的数产出。 CODE: #include //#pragma comment(linker, "/STACK

不会吃鱼的喵 479

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

HDU5902 GCD is Funny【GCD】

GCD is Funny Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2577 Accepted Submission(s): 626 Problem Description Alex has invented a new game for fun. There are n integers at a board and he perfo

海岛Blog 407

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

『HDU 5902』GCD is Funny

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5902 转载链接:http://blog.csdn.net/xtulollipop/article/details/52664876题意: 个人感想: 当时BC的时候我一看到题目想都不想 就直接用n^2的跑一遍两个数得gcd就是答案了… 当场交直接AC,玛德智障,原来出题人标程都搞错

Gavinjou大笨象的博客 524

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

[HDU 5902] GCD is Funny

一、题目

C202044zxy的博客 170

hdu5902GCD is Funny+数论

Problem Description Alex has invented a new game for fun. There are n integers at a board and he performs the following moves repeatedly: He chooses three numbers a, b and c written at the board and e

xtulollipop 1200

HDU - 5902 GCD is Funny 思维+数学推导+gcd

题意: 黑板上有n个数,任意选择其中三个,把其中两个的gcd加入到黑板上,之前的三个数删去; 问最后剩下的两个数(相同)可能是什么,会有很多种情况 思路: 首先我们可以想到的是任意两个数求gcd,然后后面每一次都用这两个数的gcd,最后就会剩下这个数了; 但是这样还不够,有可能我们求完gcd的这个数会和其他的数产生新的gcd,例如:30,42,14,15;所以答案就是n个数一些子集的gc...

床前明月光 558

HDU 5902 GCD is Funny 数学

GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a new game for fun. There are n integers at a board and he performs the following moves repeatedly: He ...

weixin_30248399的博客 120

HDU 5902 GCD is Funny(GCD)

GCD is Funny Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 468    Accepted Submission(s): 125 Problem Description Alex has invent

KeepTing 635

HDU 5902:GCD is Funny (GCD)

GCD is Funny Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 306    Accepted Submission(s): 65 Problem Description Alex has invente

小坏蛋_千千 829
上一篇: codeforces 712B Memory and Trident
下一篇: hdu5904 LCIS dp
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址