zoukankan      html  css  js  c++  java
  • 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.

    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;
    }
    

      

  • 相关阅读:
    win7下 iis配置 不能添加默认文档的 解决方案
    经典SQL语句大全
    Sql 行转列问题总结
    jQuery获取Select选择的Text和 Value(转)
    如何让虚拟目录里面的webconfig不继承网站的设置
    SQL2008 用户'sa'登录失败(错误18456)图文解决方法
    ASP.NET实现公历转农历的简单方法
    你的DNN站点慢了么?
    SQLServer2005删除log文件和清空日志的方案
    由于未能创建 Microsoft Visual C# 2008 编译器,因此未能打开项目 "xxx"
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6044606.html
Copyright © 2011-2022 走看看