博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces The Endless River
阅读量:5123 次
发布时间:2019-06-13

本文共 2916 字,大约阅读时间需要 9 分钟。

The Endless River
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
 

Description

standard input/output

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

Sample Input

Input
4 8 2 3 8 3 2 5 1 4 100 1 1
Output
3 3 3 1

Hint

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.

 

 

#include 
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;int a[100005];int b[100005];int main(){ //freopen("input.txt","r",stdin); int t; cin>>t; while(t--) { int n,d,r; cin>>n>>d>>r; int f=1; int s=1; int m=0; a[1]=1; int flag=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); while(1) { m++; f=m*d%n; if(b[f]==1) {break;} a[f]=1; s=m*r%n; if(a[s]==1) {break;} b[s]=1; } cout<
<

  

转载于:https://www.cnblogs.com/Hyouka/p/5719722.html

你可能感兴趣的文章
Java泛型的基本使用
查看>>
1076 Wifi密码 (15 分)
查看>>
noip模拟赛 党
查看>>
bzoj2038 [2009国家集训队]小Z的袜子(hose)
查看>>
Java反射机制及其Class类浅析
查看>>
Postman-----如何导入和导出
查看>>
移动设备显示尺寸大全 CSS3媒体查询
查看>>
图片等比例缩放及图片上下剧中
查看>>
【转载】Linux screen 命令详解
查看>>
background-clip,background-origin
查看>>
Android 高级UI设计笔记12:ImageSwitcher图片切换器
查看>>
Blog文章待看
查看>>
【Linux】ping命令详解
查看>>
对团队成员公开感谢博客
查看>>
java学习第三天
查看>>
python目录
查看>>
django+uwsgi+nginx+sqlite3部署+screen
查看>>
Andriod小型管理系统(Activity,SQLite库操作,ListView操作)(源代码下载)
查看>>
在Server上得到数据组装成HTML后导出到Excel。两种方法。
查看>>
浅谈项目需求变更管理
查看>>