zoukankan      html  css  js  c++  java
  • CF div2 328 C

    C. The Big Race
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 test(s)
    Input
    10 3 2
    Output
    3/10
    Input
    7 1 2
    Output
    3/7
    Note

    In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.

    这个题意读了一年。。。

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<set>
    #include<vector>
    
    using namespace std;
    
    long long int gcd(long long int a,long long int b)
    {
        return b==0?a:gcd(b,a%b);
    }
    int main()
    {
    
    
        long long int t,w,b,k=0;
        scanf("%I64d%I64d%I64d",&t,&w,&b);
        long long int m=min(w,b);
        long long int temp0=gcd(w,b);
        double lcm=(double)(w/temp0)*(double)b;
        double temp=(double)t;
        if(lcm-temp>0.01){
    
            k=min(t,m-1);
        }
    
        else{
    
            long long int lcm2=(w/temp0)*b;
            long long int temp=(t/lcm2);
            k=temp*m;
            k+=min(t%(lcm2),m-1);
        }
        long long int ans=gcd(k,t);
        printf("%lld/%lld
    ",(k/ans),(t/ans));
        return 0;
    }
    View Code
  • 相关阅读:
    一个网卡绑定多个IP和多个网卡用一个ip的设置
    Linux操纵细碎以太网卡的装配及设置2
    教你若何制作软盘版的 Linux系统防火墙
    Ubuntu Linux体系中装置GNOME初步劈脸菜单
    构筑Linux防火墙之集团用户设置防火墙1
    Linux系统Iptables端方执行按次过细讲解
    Proxy源代码分析 谈Linux收集编程身手
    Linux使用系统以太网卡的安装及设置装备陈设1
    操持Linux下Oracle Tomcat 8080端口争持2
    Linux操作体系上差别文件体系的兼容成就
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4929540.html
Copyright © 2011-2022 走看看