1.2.2 hidehandkerchief(附翻译)

HDU--2104--hide handkerchief--解题报告(辗转相除的运用) Problem DescriptionThe Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.N 阅读详情

 

Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 8026 Accepted Submission(s): 2571

Problem Description

The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.

Now I introduce the game to you. Suppose there are N people played the game ,who sit on the ground forming a circle ,everyone owns a box behind them .Also there is a beautiful handkerchief hid in a box which is one of the boxes .

Then Haha(a friend of mine) is called to find the handkerchief. But he has a strange habit. Each time he will search the next box which is separated by M-1 boxes from the current box. For example, there are three boxes named A,B,C, and now Haha is at place of A. now he decide the M if equal to 2, so he will search A first, then he will search the C box, for C is separated by 2-1 = 1 box B from the current box A . Then he will search the box B ,then he will search the box A.

So after three times he establishes that he can find the beautiful handkerchief. Now I will give you N and M, can you tell me that Haha is able to find the handkerchief or not. If he can, you should tell me "YES", else tell me "POOR Haha".

儿童的时代已经过去了。你还记得你童年时发生过的事吗?我记得我经常和朋友一起玩一个叫做皮手帕的游戏。
现在我向你介绍游戏。假设有N个人玩这个游戏,坐在地上形成一个圆圈,每个人都在他们后面拥有一个盒子。还有一个漂亮的手帕藏在一个箱子里,这是盒子之一。
然后哈哈(我的一个朋友)被叫去找手帕。但他有一个奇怪的习惯。每次他将搜索当前框中由M-1框分隔的下一个框。例如,有三个框分别命名为A,B,C,现在哈哈在A的位置,现在他决定M等于2,所以他先搜索A,然后搜索C框,C由当前框A将2-1 = 1框B分开。然后他将搜索框B,然后他将搜索框A。
所以三次后,他建立了他可以找到美丽的手帕。现在我会给你N和M,你能告诉我,哈哈能否找到手帕吗?如果他能,你应该告诉我“是”,否则告诉我“可怜的哈哈”。

Input

There will be several test cases; each case input contains two integers N and M, which satisfy the relationship: 1<=M<=100000000 and 3<=N<=100000000. When N=-1 and M=-1 means the end of input case, and you should not process the data.

会有几个测试用例; 每个情况输入包含两个整数N和M,满足关系:1 <= M <= 100000000和3 <= N <= 100000000。 当N = -1和M = -1意味着输入大小写的结束,并且您不应该处理数据。

Output

For each input case, you should only the result that Haha can find the handkerchief or not.

对于每一个输入案例,你只应该得到哈哈可以找到手帕的结果。

Sample Input

3 2
-1 -1

Sample Output

YES

本题解题难度在于如何把查找手帕这个过程抽象出求公约数的过程

c++

#include <iostream>  
#include<string>  
using namespace std;
int gcd(int a, int b){ //函数用于递归求最大公约数
	if (b == 0)
		return a;  
	else 
		return gcd(b, a%b);  
}  
int main(){
     int m, n;  
    while (cin>>n>>m){  
        if (n == -1 && m == -1)
			break;  
        if (gcd(n,m)!=1)
			cout << "POOR Haha" << endl;  
        else   //最大公约数为1
            cout << "YES" << endl;  
    } 	
    return 0;  
} 

运行截图



Hidebug_unity调试功能扩展 Hidebug_unity调试功能扩展,一键开关日志,屏幕显示日志,本地文件写入日志. 立即下载

相关推荐

Tushare Day2——了解stock_basic数据并根据行业和地区进行统计

了解stock_basic数据 1  stock_basic基础信息2  导入包和stock_basic数据、查看基本信息3  根据行业列进行统计3.1  1.先把不同行业列举出来,看一下一共有多少种行业3.2  2.统计每个行业分别有多少家公司3.3  3.把行业从array的二维数组形式变成list形式3.4  4.把行业从list形式转换成文本形式3.5&nbsp

绒绒的Routine 2796

HDU ACM Steps 1.2.2 hide handkerchief 详解

文章目录一、问题描述二、题解1.转化为最大公约数2.参考代码 一、问题描述 hide handkerchief The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. Now I introduce the.

qq_40744839的博客 263

Dify沙箱权限配置实战:解决‘operation not permitted‘报错的完整指南

本文详细解析了Dify平台中常见的'operation not permitted'报错根源,即沙箱安全机制对系统调用的限制。通过实战步骤,指导用户定位并修改config.yaml配置文件,精准配置allowed_syscalls白名单以解决权限问题,涵盖从文件操作、进程控制到网络通信等关键系统调用的编号详解与配置示例,帮助用户在保障安全的前提下,顺利运行依赖特定库的代码工作流。

tech5的博客 1202

hide handkerchief/隐藏手帕

一:杭电原题摘录 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=6 杭电1.2.2二.题目分析 大致翻译一下,n个人围成一个圈,大家玩小时候的丢手帕游戏,不同的是我们身后有一个箱子,手帕藏在某一个人的箱子里,HaHa来找,每一次他都会跳过m-1个人。问你H...

2020 950

新手入门机器学习案例(附源代码)

无

guguo666的博客 6656

从零开始:用君正T23ZN打造智能门锁双摄系统(含代码示例与调试技巧)

本文详细介绍了基于君正T23ZN视频处理芯片构建智能门锁双摄系统的完整实战方案。内容涵盖硬件选型与核心电路设计、软件开发环境搭建、双摄驱动框架、图像信号处理(ISP)调优、人脸识别算法集成与性能优化,以及系统调试与稳定性保障。文章提供了丰富的代码示例和调试技巧,旨在帮助嵌入式开发者高效实现具备人脸识别与监控功能的低功耗智能门锁视觉系统。

opencv7vision的博客 716

杭电oj2104题hide handkerchief

Problem DescriptionThe Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. No

blingzlh的博客 1125

KMS服务器一键部署与激活实战指南

本文详细介绍了KMS服务器的一键部署与激活实战指南,包括快速入门、安装步骤、服务管理技巧及常见问题排查。特别针对Windows和Mac用户提供了Office激活的具体操作步骤,并分享了高级配置与优化方案,帮助IT管理员高效管理批量授权激活。

weixin_29305313的博客 461

HDOJ 2104 hide handkerchief(判断互质)

hide handkerchief Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3335    Accepted Submission(s): 1579 Problem Description The Child

Chunzhen的博客 3022

从零开始:用ADS仿真设计一个2.4GHz Wi-Fi低噪声放大器(含完整电路图)

本文提供了一份详细的ADS软件仿真指南,手把手教你从零开始设计一个2.4GHz Wi-Fi低噪声放大器。内容涵盖核心指标理解、晶体管选型与建模、匹配网络设计、偏置电路集成,并通过S参数仿真、噪声优化及线性度验证等步骤,最终呈现完整的优化电路图,助力射频初学者掌握LNA设计全流程。

weixin_29197835的博客 806

Godot 4.x 实现 JRPG 回合制战斗系统:架构、状态机与实战优化

游戏开发中,状态机是管理复杂逻辑流转的核心设计模式,尤其在回合制战斗这类事件驱动的场景中。其原理是通过定义有限的状态和明确的转移条件,来控制系统在不同阶段的行为,从而实现清晰、可维护的流程控制。这项技术的价值在于能够将杂乱的条件判断代码结构化,降低模块间的耦合度,提升代码的可读性和可扩展性。在游戏开发领域,状态机广泛应用于角色AI、UI流程、战斗系统等场景。本文以Godot引擎为例,深入探讨如何运用节点与信号驱动架构,构建一个健壮的JRPG(日式角色扮演游戏)回合制战斗系统。内容涵盖从核心的**状态机**设

weixin_33749242的博客 499

hide handkerchief (gcd)

hide handkerchief The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. N...

codeswarrior的博客 361

Buck电源设计常见的一些问题(四)MOS管振荡抑制方法(二)

另一方面,开关振铃为远超开关频率的高频振铃,并伴随很高的 dV/dt,会带来传导和辐射的 EMI 问题,可能会使得终端产品不能通过 EMI 标准测试,更严重时甚至会干扰开关电源自身的信号电路或临近的其他功能电路的正常工作。选用二极管反向特性好的器件;该电路可等效成图 3 中 LC 谐振电路,新的 LR和 CR为 Lp1、Lp5,Lp3, Lp4, CD等所有参与振铃的寄生感容的复合值。通常 Snubber 的 Csnub取值在数 nF 以上,在振铃频率 fR(加了 snubber 后)下的阻抗很小。

小幽余生不加糖 2892

hide handkerchief

问题描述 : The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends....

anchouman0644的博客 242

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU——2104 hide handkerchief

hide handkerchief Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3401    Accepted Submission(s): 1608 Problem Description The Chi

逝水流年轻染尘 559

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

杭电2104hide handkerchief

hide handkerchief Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5252 Accepted Submission(s): 2446Problem Description The Children’s Day

编程小白的进阶之路 888

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

hdu hide handkerchief

hide handkerchief Time Limit: 10000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Problem Description The Children’s Day has passed for some days .Has you remembered something ...

weixin_34307464的博客 236

杭电ACM 2104: hide handkerchief

原创作品 转载请注明出处http://blog.csdn.net/always2015/article/details/45370385这道题目刚开始没看懂,看了很久,意思是n个人围成一个圈,大家玩找手帕游戏,手帕藏在某一个人的箱子里,Haha来找,每一次他都会跳过m-1个人。问你Haha是不是一定能找到手帕。因为Haha找的次数是无限的,可以永远找下去,所以,只要他能把所有的人都找一遍就一定能找

去实验室,奔跑吧 2598

A - hide handkerchief

A -hide handkerchief Time Limit:3000MSMemory Limit:32768KB64bit IO Format:%I64d & %I64u Description The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game c...

alexlioooo的博客 175

HDU-寻找大富翁

寻找大富翁 点击打开链接   浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. Input 输入包含多组测试用例. 每个用例首先包含2个整数n(0 n和m同时为0时表示输入结束. Output 请输出乌镇前m个大富翁的财产数,财产多的排前面,如果大富翁不足m个,则全部输出,每组输出占一行. Sample Input 3 1 2 5 -1 5 3 1 2 3 4 5

crystaljy的博客 477

(丢手绢)hdu 2104 hide handkerchief

hide handkerchief Problem Description The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerch

王小二的博客 480

[HDU]ACM Steps-Chapter One-Section 2

1.2.1 Problem Description Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front whe

EchoSun's Blog 717

一列数的规则如下: 1、1、2、3、5、8、13、21、34…… 求第30位数是多少, 用递归算法实现

前言        首先声明,这道题解法来自博客:https://blog.csdn.net/qq_16633405/article/details/79211002        不过原文没有给出解释,想了很久才想出来   解题思路 这是ACM中比较常见的一类题,本身找规律是不难的,无非就是前两个个数相加等于后一个数,按照常规的解法是很容易的,例如   java源码 pub...

zhen921的博客 1万+
上一篇: 排序算法入门——直接插入排序
下一篇: 排序算法入门——希尔(shell)排序
zhen921
博客等级 码龄9年 58粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值