• wolf and rabbit


    模拟过程,推出场景

    while( n > m ? ( n = n%m ) : ( m = m%n ) );
            if(n+m==1)
                 printf("NO\n");
            else printf("YES\n");

    需要判断狼是否可以到达每一个洞,由此可以得出这样的式子

    设洞的位置为n,总的洞数量为m,狼查找的间隔为k;

    a,b为任意正整数

    (n+a*m)=b*k

    n=b*k-a*m

    这样问题就转化为用欧几里德扩展定理可以求解的问题了,即求解是否存在这样的a,b是上式成立,

    但是这样就需要求许多次,遍历m次,由欧几里德扩展定理可知等号前的数一定要符合是k,m的最大公约数的倍数,也就是说如果求出k,m的最大公约数不是1,那么在1到n之间总会存在至少一个数不能整除该最大公约数,于是就的出安全洞存在

    题目描述

    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.

    输入

    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

    输出

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

    样例输入

    2
    1 2
    2 2

    样例输出

    NO

    YES

    #include<stdio.h>
    int main()
    {
        int n, m, a;
        int i, j;
        scanf( "%d\n", &a );
        while( a-- )
        {
            scanf( "%d%d", &m, &n );
            while( n > m ? ( n = n%m ) : ( m = m%n ) );
            if(n+m==1)
                 printf("NO\n");
            else printf("YES\n");
        }
        return 0;
    }

  • 相关阅读:
    【和我一起学python吧】Python安装、配置图文详解
    【和我一起学python吧】初学Python,版本如何选择?
    CSS使用简介
    css样式表中的样式覆盖顺序
    转载-ActiveMQ通过JAAS实现的安全机制
    消息队列开发记录笔记-ActiveMQ
    转载-使用消息队列的 10 个理由
    在linux或mac终端下将命令结果输出到文件保存
    ideviceinstaller命令(类似android的adb)
    mac安装mysql及导库
  • 原文地址:https://www.cnblogs.com/zsj576637357/p/2259305.html
Copyright © 2020-2023  润新知