zoukankan      html  css  js  c++  java
  • Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

    C. The Big Race

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/592/problem/C

    Description

    Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.

    Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.

    While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).

    Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.

    Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?

    Input

    The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.

    Output

    Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.

    The fraction (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.

     

    Sample Input

    10 3 2

    Sample Output

    3/10

    HINT

    题意

    终点可以在1-t里面随便选择一个

    终点之后都是陷阱,然后有两个人在比赛,一个人一步走w米,一个人一步走b米,谁能不越过终点的情况,走的最远,就算谁赢

    然后问你选择平等的概率是多少

    题解:

    找规律,找规律

    对于每个lcm我们可以当成新的一轮是吧,然后每个lcm中,我们可以选择min(w,b)个,作为起点

    然后我们搞一搞就好了

    这儿唯一遇到的情况就是,当lcm(w,b)> t的时候,这时候就应该输出min(w,b)-1/t

    但是我们怎么判断lcm(w,b)>t呢?log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0)就好了

    代码

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    long long t,w,b;
    long long gcd(long long a,long long b)
    {
        return b==0?a:gcd(b,a%b);
    }
    long long lcm(long long a,long long b)
    {
        return a/gcd(a,b)*b;
    }
    int check(long long a,long long b,long long c)
    {
        if(log(a*1.0) + log(b * 1.0) - log( gcd(a,b)*1.0 )> log (c * 1.0))
            return 1;
        return 0;
    }
    
    int main()
    {
        cin>>t>>w>>b;
        if(w==b)
        {
            printf("1/1");
            return 0;
        }
        long long ans1,ans2=t;
        if(check(w,b,t))
        {
            ans1 = min(w-1,min(b-1,t));
        }
        else
        {
            long long kkk = lcm(w,b);
            long long ggg = t / kkk;
            long long Ans1;
            if(ggg * kkk + min(w,b) <= t)
                Ans1 = (ggg + 1)* min(w,b) - 1;
            else
                Ans1 = ggg * ( min(w,b) -  kkk )  + t;
            ans1 = Ans1;
        }
        printf("%lld/%lld",ans1/gcd(ans1,ans2),ans2/gcd(ans1,ans2));
    }
  • 相关阅读:
    TFIDF
    奇异值分解(singular value decomposition,SVD)
    (转载)先验分布
    在博客中写公式的两种方法
    linux 下配置JDK JRE ECLIPSE TOMCAT
    tensor decomposition
    Form界面设置只读
    FORM LOV特性
    在Oracle Form中,如何实现自动编号(行号)的功能
    文件夹错误frm41097,frm41053
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4927831.html
Copyright © 2011-2022 走看看