ACM step 1.2.3 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 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".

求最大公约数的一道题,如果m,n不互质的话就会有一些同学永远不会被点到。

//

//  main.c

//  hdu1.2.3

//

//  Created by wuxi on 14-10-27.

//  Copyright (c) 2014年 wuxi. All rights reserved.

//

#include <stdio.h>

int gcd(int x,int y)

{

if (x%y==0) return y;

return  gcd(y,x%y);

}

int main() {

int m,n,q;

while(1){

scanf("%d%d",&m,&n);

if (m==-1 && n==-1) break;

if (m>=n )

q=gcd(m,n);

else  q=gcd(n,m);

if (q==1) printf("YES\n");

else printf("POOR Haha\n");

}

return 0;

}

时间: 2024-12-17 04:13:55

ACM step 1.2.3 hide handkerchief的相关文章

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415

hide handkerchief

Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5029 Accepted Submission(s): 1670   Problem Description The Children’s Day has passed for some days .Has you remembered something happened at your

HDU 2104 hide handkerchief(辗转相除法--GCD)

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

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 happened at your childhood? I remembered I often play

(HDUStep 1.2.2)hide handkerchief(用辗转相除法来求最大公约数)

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

hide handkerchief(hdu2104)

思考:这种找手绢就是,在判断是否互质.用辗转相除法(用来求最大公约数:a)进行判断.r=a%b;a=b;b=r;循环限制条件:除数b=0是结束除法.如果这时被除数a=1,则表示两个互质. #include<stdio.h> int main() { int N,M; char d; while(scanf("%d%d%c",&N,&M,&d)!=EOF) { if(N==-1&&M==-1) break; int r; while(M

ACM step 1.2.2 Text Reverse

gnatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. 一个简单的回文输出..然后请原谅我的冗长的代码,之前很久没写程序了.. // //  main.cpp //  hdu1.2.2 // //  Created by wuxi on 1

100行代码实现简单目录浏览器制作

给大家分享使用Lae软件开发工具开发小应用程序的过程,希望大家喜欢! 界面部分我们用lae软件开发工具实现,无需写代码,业务逻辑部分使用Lae软件开发平台自带的LuaIDE编辑器,使用100行lua代码完成简单目录浏览器的制作. lae软件下载地址: https://github.com/ouloba/laetool.git lae软件下载地址(国内):https://pan.baidu.com/s/1ckMy0Q 相关视频: http://www.tudou.com/listplay/aly7

hdu 2104(判断互素)

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