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.

Input

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 nd 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.

Output

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.

Example
input
4
8 2 3
8 3 2
5 1 4
100 1 1
output
3
3
3
1
Note
                                  

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的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 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 ...

  3. 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 ...

  4. 2016 Al-Baath University Training Camp Contest-1 B

    Description A group of junior programmers are attending an advanced programming camp, where they lea ...

  5. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. HDU 1724 Ellipse(数值积分の辛普森公式)

    Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...

  2. SQL Server数据库性能优化(一)之 优化SQL 语句

    最近工作上基本没什么需求(好吧 不是最近是好久了,所以随便看看基础的东西来填补自己的空白) 原文出自:http://www.blogjava.net/allen-zhe/archive/2010/07 ...

  3. angular Creating a Directive that Adds Event Listeners

    <span my-draggable>Drag ME</span> angular.module('dragModule', []) .directive('myDraggab ...

  4. app_field.clear_dependent_fields

    可以调用APP_FIELD.clear_dependent_fields和APP_FIELD.set_dependent_field来将两个(或多个)Item建立关联,当一个为空时,另一个不可录入,反 ...

  5. 夺命雷公狗ThinkPHP项目之----企业网站11之栏目的删除完成

    我们删除要在分类模型中添加一个_before_delete的钩子函数,而且在删除一个分类时候,如果这个分类有子分类就不允许删除 model层代码如下所示: <?php namespace Adm ...

  6. MOPSO 多目标例子群优化算法

    近年来,基于启发式的多目标优化技术得到了很大的发展,研究表明该技术比经典方法更实用和高效.有代表性的多目标优化算法主要有NSGA.NSGA-II.SPEA.SPEA2.PAES和PESA等.粒子群优化 ...

  7. 【py分析】

    pyQuery pyQuery 是 jQuery 在 python 中的实现,能够以 jQuery 的语法来操作解析 HTML 文档,十分方便.使用前需要安装,easy_install pyquery ...

  8. cvLoadImage函数解析 cvLoadImageM()函数

    1.函数原型:IplImage* cvLoadImage( const char* filename, int flags=CV_LOAD_IMAGE_COLOR ); filename :要被读入的 ...

  9. SQL SERVER2000中订阅与发布的具体操作

    同步过程 一.准备工作,如果完成则可跳过. 1.内网DB服务器作为发布服务器,外网DB服务器作为订阅服务器. 发布服务器和订阅服务器上分别创建Windows用户jl,密码jl,隶属于administr ...

  10. ID3DXMesh接口 创建自己的立方体网格

    D3DXCreateMeshFVF 首先创建一个ID3DXMesh接口. ID3DXMesh接口的说明可以参数龙书. 这里主要是用代码来讲解: #define VERTEX_FVF (D3DFVF_X ...