zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    互联网中的公钥与私钥
    Apache的order、allow、deny
    Linux进程中TIME_OUT解析
    no xxx find in java.library.path
    检测 USB 设备拨插的 C# 类库:USBClassLibrary
    C# 实现的异步 Socket 服务器
    javascript制作公式编辑器,函数编辑器和图形绘制
    浏览器内部工作原理
    10 款基于 jQuery 的切换效果插件推荐
    DIV焦点事件详解 --【focus和tabIndex】​
  • 原文地址:https://www.cnblogs.com/zsj576637357/p/2259305.html
Copyright © 2011-2022 走看看