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 ...
随机推荐
- Ejb: remote调用
用的是wildfly 9.0.2 一:在myeclipse中新建wildfly 9.0.2的server(如何新建去网上搜) 二:修改wildfly server的argument(在run conf ...
- JavaOOP QuickHit项目分析
项目需求:游戏等级6级,随机字符串每级长度不同.每升一级减少比较次数,但是字符串长度相应增加!每级总分数不同,如果游戏中途输入错误则游戏退出!玩家每次在规定时间内输入字符串的同时,打印出游戏难度等级. ...
- linux tomcat 配置
http://www.cnblogs.com/xdp-gacl/p/4097608.html
- 夺命雷公狗---DEDECMS----24dedecms让网站头部分离
我们这里来做一个让网站头部分离的工作,我们先看下index.htm的模版, 这里很明显就是用了一个div包围着而已,那么我们在模版目录下创建一个head.htm,如下所示: 然后我们再将刚才div里面 ...
- Web服务器处理HTTP压缩之gzip、deflate压缩
现如今在处理http请求的时候,由于请求的资源较多,如果不启用压缩的话,那么页面请求的流量将会非常大.启用gzip压缩,在一定程度上会大大的提高页面性能. 目录 一.什么是gzip 二.什么是de ...
- 给uefi引导的方式安装archlinux
基本就是照着官方的wiki来的,不过官方的wiki的内容太杂了,或许我们需要的是一个瀑布似的流程. 其实大体上与mbr引导的方式类似,只凭借回忆说一下有区别的地方,等下一次有机会的时候再验证一下. 换 ...
- linux时区的设置
到目前为止,个人的理解就是linux中设置时区就是修改配置文件 /etc/localtime 而通常的做法就是让这个文件作为符号链接,链接到 /usr/share/zoneinfo/ 中的某个特定的时 ...
- zw版【转发·台湾nvp系列例程】halcon与delphi系列例程
zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...
- opencv常用数据结构之:IplImage
typedef struct_IplImage{ int nSize; //IplImage大小 int ID; //版本(=0) int nChannels; //大多 ...
- OpenStack主机列表接口
如之前讨论,openstack提供一套接口给运维管理平台,运维管理平台通过获取到的IP地址对主机进行监控. 接口名 请求地址 请求方法 请求cookie 请求头 返回值 返回值使用 登录 ...