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 ...
随机推荐
- HDU 1724 Ellipse(数值积分の辛普森公式)
Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...
- CSS_01_CSS和html结合的方式3、4
第01步:编写第01个css样式:div.css @charset "utf-8"; /*第01步:定义div:背景色.字体颜色*/ div{ background-color:# ...
- <构建之法>之一至二章
身在大学,却想起了在高中的生活和初中的生活,特别是初中的生活,为什么这么说呢!因为<构建之法>,看了其中的两章的内容,为什么想到了初中和高中的生活呢,因为在高中和初三的时候看的最多的就是课 ...
- Aspose.cell处理Excel
(一)从数据库中读取数据写入Excel中 方法1: 步骤:1.建立一个新的项目,引用动态链接库Aspose.dll 2.见下面的原代码 using System;using System.Collec ...
- paper 32 :svm参数优化的进展
从今天开始,我的微信公众号“天空之窗”就暂且停止更新内容了,专心搞研究!上午从师姐那儿淘到一份关于faruto讲解的Libsvm-FarutoUltimate3.1 based on libsvm-3 ...
- java mvc控制器基本传值方式
控制器----- @RequestMapping(value = "MatchDetail", method = RequestMethod.GET) public ModelAn ...
- mongo语句优化分析
参考原文:http://www.mongoing.com/eshu_explain3 理想的查询状态由以下两种 普通查询: nReturned=totalKeysExamined & tota ...
- linux系统的时间调整
以centos为例,其它系统应该是一样或者类似的. 需要用到两个命令: date 和 hwclock 其中 date 命令由 coreutils 这个包提供, hwclock 命令由 util-lin ...
- JetBrains WebStorm 8 注册码
UserName:William===== LICENSE BEGIN =====45550-1204201000001SzFN0n1bPII7FnAxnt0DDOPJAINauvJkeVJBuE5b ...
- Sql Server 检测死锁的SQL语句
首先创建一个标量值函数DigLock,用来递归检测SqlServer中的每一个会话是否存在加锁循环,如果该函数最终返回1则表示检测到了加锁循环 (也就是说检测到了死锁),如果最终返回0则表示没有检测到 ...