CF1304A Two Rabbits 题解

description:

  • 有一条数轴,上面有两只兔子。

  • 一只兔子位于 x x x 坐标,每秒跳 a a a 个单位,另一只位于 y y y 坐标,每秒跳 b b b 个单位,保证 x < y x<y x<y ,两只兔子相向而行。

  • 请你求出两只兔子是否会在整数秒相遇,如果是,打印出相遇的那一秒(初始时间从 0 0 0 开始),如果无法在整数秒相遇,则输出 -1

  • translate by @ShineEternal

solution:

我们发现兔子一定会相遇,只是可能不在整数秒,根据相遇问题的公式,我们只需要判断 ( y − x )   m o d   ( a + b ) (y-x)\bmod (a+b) (yx)mod(a+b) 是否为 0 0 0 即可。(即是否为整数秒)

code:

#include<cstdio>
using namespace std;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		long long x,y,a,b;
		scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
		long long z=y-x;
		long long c=a+b;
		if(z%c==0)
		{
			printf("%d\n",z/c);
		}
		else
		{
			printf("-1\n");
		}
	}
	return 0;
} 
下面有篇英文课文,请编程找出课文中所有的单词,统计单词出现的次数,统计时不区分字母的大小写,最后按出现的次数从大到小显示出现3次以上各个单词及次数。例如,结果显示如下: the 18 a 14 puma 9 in 8 it 8 ...(略) 英文课文如下: Pumas are large, cat-like animals which are found in America. When reports came into London Zoo that a wild puma had been spotted forty-five miles south of London, they were not taken seriously. However, as the evidence began to accumulate, experts from the Zoo felt obliged to investigate, for the descriptions given by people who claimed to have seen the puma were extraordinarily similar. The hunt for the puma began in a small village where a woman picking blackberries saw 'a large cat' only five yards away from her. It immediately ran away when she saw it, and experts confirmed that a puma will not attack a human being unless it is cornered. The search proved difficult, for the puma was often observed at one place in the morning and at another place twenty miles away in the evening. Wherever it went, it left behind it a trail of dead deer and small animals like rabbits. Paw prints were seen in a number of places and puma fur was found clinging to bushes. Several people complained of 'cat-like noises' at night and a businessman on a fishing trip saw the puma up a tree. The experts were now fully convinced that the animal was a puma, but where had it come from ? As no pumas had been reported missing from any zoo in the country, this one must have been in the possession of a private collector and somehow managed to escape. The hunt went on for several weeks, but the puma was not caught. It is disturbing to think that a dangerous wild animal is still at large in the quiet countryside.
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShineEternal

觉得好就给点鼓励呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值