2016 Al-Baath University Training Camp Contest-1 H
Description
You've possibly heard about 'The Endless River'. However, if not, we are introducing it to you. The Endless River is a river in Cambridge on which David and Roger used to sail. This river has the shape of a circular ring, so if you kept sailing forward you wouldn't find an end, and that's why it was called 'endless'. The river is exactly n meters long. Each minute, David moves d meters forward while Roger movesr meters forward; they start sailing from the same position at the same time, moving in the same direction. At the beginning of each minute, each of them leaves a marker at his current place (they don't put any markers at the beginning of the race). Determine the number of minutes before two markers (of different people) are placed at the same position.
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each of the following lines represents a test case and contains three space-separated integers n, d and r (1 ≤ n, d, r ≤ 100000) denoting the length 'in meters' of the river, David's speed and Roger's speed (as explained in the statement above) respectively.
For each test case print a single line containing one integer: the number of minutes before two markers (of different people) are placed at the same position.
4
8 2 3
8 3 2
5 1 4
100 1 1
3
3
3
1
In the first case, we have n = 8, d = 2 and r = 3. They start at the first space which is denoted with 'start'. Red color denotes David's markers, green for Roger's markers, blue denotes that two markers (of different people) are placed. At the beginning (0 minutes passed), no markers are placed. After 1 minute passes, David is at the third space and Roger is at the fourth. After 2 minutes pass, David is at the fifth space and Roger is at the seventh. After 3 minutes pass, David is at the seventh space and Roger is at the minute, so when David places his marker, two markers are placed at the seventh space and the answer is 3 minutes.
题意:两个人从同一个地方出发,速度为d,r,问什么时候会路过同一个地方
解法:暴力
#include<bits/stdc++.h>
using namespace std;
int a[1000010],b[1000010];
int main()
{
int t;
int n,m,k;
cin>>t;
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>n>>m>>k;
int num=0;
int sum1,sum2;
sum1=m;
sum2=k;
while(1)
{
num++;
sum1%=n;
sum2%=n;
a[sum1]=1;
b[sum2]=1;
// cout<<sum1<<" "<<sum2<<endl;
if((a[sum1]&&b[sum1])||(a[sum2]&&b[sum2]))
{
cout<<num<<endl;
break;
}
sum1+=m;
sum2+=k;
}
}
return 0;
}
2016 Al-Baath University Training Camp Contest-1 H的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)
2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 B
Description A group of junior programmers are attending an advanced programming camp, where they lea ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
随机推荐
- 根据搜素的字符串改变label包含该字符串的文字
http://www.2cto.com/kf/201504/391811.html NSString *text =@"人生若只如初见"; //判断字符串所在的位置,并不区分大小写 ...
- poj: 2262
简单题 #include <iostream> #include <stdio.h> #include <string> #include <stack> ...
- java反射机制简介
1.字节码.所谓的字节码就是当java虚拟机加载某个类的对象时,首先需要将硬盘中该类的源代码编译成class文件的二进制代码(字节码),然后将class文件的字节码加载到内存中,之后再创建该类的对象 ...
- bzoj 4237稻草人
按x轴进行分治,将[l,r]分成[l,mid]和[mid+1,r],左下角点x值在[l,mid]中,右上角点x值在[mid+1,r],然后将[l,r]中的所有点按y轴排序,按顺序扫描,若扫描到左下角点 ...
- Spark on Yarn
Spark on Yarn 1. Spark on Yarn模式优点 与其他计算框架共享集群资源(eg.Spark框架与MapReduce框架同时运行,如果不用Yarn进行资源分配,MapReduce ...
- java-excel导出
java excel导出分为两种2003年的格式和2007年的格式. 2003年的xls一个sheet限制65536. 2007年的xlsx限制为1048576. jxl导入2003 gradle j ...
- 实施费用也能DIY--走出软件作坊:三五个人十来条枪 如何成为开发正规军(九)[转]
上次咱们讲完了开发费用的计算,很多人在后面跟帖在那里算费用. 有人说:你把程序员都不当人,94天,一天都不休息啊. 我想答曰:94天,是工作时间.不算双休日在里面.也就是说,实际的开发周期长度是94+ ...
- where 子句和having子句中的区别
1.where 不能放在GROUP BY 后面 2.HAVING 是跟GROUP BY 连在一起用的,放在GROUP BY 后面,此时的作用相当于WHERE 3.WHERE 后面的条件中不能有聚集函数 ...
- Openstack的计算节点的nova-network异常中止及实例无法删除排错过程
在预生产环境(172.17.46.2)发现无法删除实例,可以对实例做暂停,恢复操作. 查询原因发现计算节点的nova-network异常 [root@node-12 ~]# /etc/init.d/o ...
- OpenStack 服务状态检查
openstack服务不正常 使用命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [root@node-5 TimaIaas]# nova- ...