hdu 2.2.4 Wolf and Rabbit 解题心得

原题:

Description

There is a hill with n holes around. The holes are signed from 0 to n-1.

A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.

Input

The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648).

Output

For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line.

Sample Input

2
1 2
2 2

Sample Output

NO
YES

分析:

这个题题意是一个圆形的山环绕着兔子洞,狼会每隔一定的洞数会进洞找兔子,因为是圆所以可以循环,

必定有规律,我是写个暴力程序,打印出20组数据找出规律的,规律就是互质就有遗漏,否则没有遗漏

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int gcd(int a, int b)
{
    if (b == 0)
    {
        cout << a << endl;
        return a;
    }
    else
    {
        cout << gcd(b, a%b) << endl;
        return gcd(b, a%b);
    }
}
int main()
{
    gcd(6, 4);
    int t;
     cin >> t;
    int a, b;
    while (t--)
    {
        cin >> a >> b;
        if (gcd(a, b) == 1)
        {
            puts("NO");
        }
        else
        {
            puts("YES");
        }
    }

    return 0;
}
时间: 2024-12-19 01:59:08

hdu 2.2.4 Wolf and Rabbit 解题心得的相关文章

(hdu 2.2.4)Wolf and Rabbit(一个圆有n个数,每次数m个数,看能否遍历这个圆)

题目: Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2021 Accepted Submission(s): 1146   Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

HDU:1465不容易系列之一 解题心得

原题; Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选

HDU 4911 Inversion - 疯狂的癫子 解题心得

原题: Description bobo has a sequence a 1,a 2,…,a n. He is allowed to swap two adjacent numbers for no more than k times. Find the minimum number of inversions after his swaps. Note: The number of inversions is the number of pair (i,j) where 1≤i<j≤n an

hdu 1557 权利指数 ( 二进制枚举子集) 解题心得

原题: Description 在选举问题中,总共有n个小团体,每个小团体拥有一定数量的选票数.如果其中m个小团体的票数和超过总票数的一半,则此组合为“获胜联盟”.n个团体可形成若干个获胜联盟.一个小团体要成为一个“关键加入者”的条件是:在其所在的获胜联盟中,如果缺少了这个小团体的加入,则此联盟不能成为获胜联盟.一个小团体的权利指数是指:一个小团体在所有获胜联盟中成为“关键加入者”的次数.请你计算每个小团体的权利指数. Input 输入数据的第一行为一个正整数T,表示有T组测试数据.每一组测试数

HDU 1222: Wolf and Rabbit

HDU 1222: Wolf and Rabbit ///@author Sycamore, ZJNU ///@accepted_on 2017-01-24 #include<iostream> using namespace std; unsigned gcd(unsigned a, unsigned b) { return b == 0 ? a : gcd(b, a % b); } int main() { int P; cin >> P; while (P--) { unsi

HDU 1222 Wolf and Rabbit (扩展欧几里德应用)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6292    Accepted Submission(s): 3142 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

hdu 1222 Wolf and Rabbit (GCD)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5502    Accepted Submission(s): 2765 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

HDU-1222 Wolf and Rabbit (欧几里得定理)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7684    Accepted Submission(s): 3870 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

Wolf and Rabbit(gcd)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5922    Accepted Submission(s): 2972点我 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1