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.
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.
2 1 2 2 2
NO YES
分析: 当数据为1 2时 狼进的洞0 1 0 1所以no;数据2 2狼进的洞0 0 0 0......所以yes;所以延伸为求n,m,最大公约数是否为1;若1 no,否则yes;
代码:
#include<stdio.h>
int main()
{int t;
long int n,m,k;
scanf("%d",&t);
while(t--)
{
scanf("%ld%ld",&n,&m);
while(m!=0)
{
k=n%m;
n=m;
m=k;
}
if(n==1)
printf("NO\n");
else printf("YES\n");
}
return 0;
}
本文探讨了一种基于数学原理的安全洞穴问题,通过分析狼寻找兔子的路径来确定是否存在安全洞穴。输入包括多组测试数据,每组数据包含两个整数m和n,输出则是判断是否存在安全洞穴。文章提供了完整的C语言实现代码,并揭示了最大公约数为1时不存在安全洞穴的结论。
309

被折叠的 条评论
为什么被折叠?



