您的位置:首页 > 其它

Codeforces Round #328 (Div. 2) 592 C. The Big Race

2016-01-26 04:23 344 查看
题意:有两个这什么…



他们两个要比赛,他们第一个一步跨w米,第二个一步跨b米

现在有个长为t米的赛道,t米后边全是陷阱

现在让你当裁判,你可以选择1~t米里边任意长度当作终点

然后两个比赛 比赛规则是 走任意步数,但是不能超过终点,可以到达

距离终点最近的获胜

问你有多少的几率使两个人距离终点的米数一样 化为最简分数的形式(注意1/1

思路:

这个一看就知道米数一样只有两种情况

第一种 能让这两个一步都不跨的距离作为终点

第二种

x为w和b的最小公倍数 终点的距离t要满足 t-t/x*x

[code]#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define rfor(i,a,b) for(i=a;i<=b;++i)
#define lfor(i,a,b) for(i=a;i>=b;--i)
#define sfor(i,a,h) for(i=h[a];i!=-1;i=e[i].next)
#define mem(a,b) memset(a,b,sizeof(a))
#define mec(a,b) memcpy(a,b,sizeof(b))
#define cheak(i) printf("%d ",i)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define inf 0x3f3f3f3f
#define lowbit(x) (x&(-x))
typedef long long LL;
#define maxn 100005
#define maxm maxn*maxn
#define lson(x) (splay[x].son[0])
#define rson(x) (splay[x].son[1])
LL t;
int judge(double a,double b)
{
    a*=b;
    if(a>t) return 1;
    return 0;
}
LL gcd(LL a,LL b)
{
    if(a==0) return b;
    return gcd(b%a,a); 
}
int main()
{
    LL w,b;
    scanf("%lld%lld%lld",&t,&w,&b);
    if(w==b)
    {
        printf("1/1\n");
        return 0;
    }
    LL ans=min(w-1,min(t,b-1));
    LL x=gcd(w,b);

    if(judge(w/x,b))
    {
        LL x=gcd(ans,t);
        printf("%lld/%lld\n",ans/x,t/x);
        return 0;
    }
    x=(w/x)*b;
    LL q=t/x;
    if(q)
    {
        ans+=(q-1)*min(w,b);
        ans+=min(w,min(b,t-q*x+1));
    }
    x=gcd(ans,t);
    printf("%lld/%lld\n",ans/x,t/x);
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: