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;
    }

  • 相关阅读:
    光棍节奉献10款chart插件 节日快乐.
    平安夜分享2款下拉菜单(CSS版本和JQuery版本)
    MVC 中T4扫盲贴
    解析JQuery 的Bind()事件
    Null在从数据库读取的时候的一点点小阴谋
    JQuery 动画效果集锦
    VS2010支持的6款UML简介
    T4系列文章之2:T4工具简介、调试以及T4运行原理
    既然结构也可以继承接口
    css float 之 clear
  • 原文地址:https://www.cnblogs.com/zsj576637357/p/2259305.html
Copyright © 2011-2022 走看看