zoukankan      html  css  js  c++  java
  • codeforces 上的找两人的幸运天

    Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days [la;ra] are lucky, then there are some unlucky days: [ra+1;la+ta1], and then there are lucky days again: [la+ta;ra+ta] and so on. In other words, the day is lucky for Alice if it lies in the segment [la+kta;ra+kta] for some non-negative integer k

    .

    The Bob's lucky day have similar structure, however the parameters of his sequence are different: lb

    , rb, tb. So a day is a lucky for Bob if it lies in a segment [lb+ktb;rb+ktb], for some non-negative integer k

    .

    Alice and Bob want to participate in team competitions together and so they want to find out what is the largest possible number of consecutive days, which are lucky for both Alice and Bob.

    Input

    The first line contains three integers la

    , ra, ta (0larata1,2ta109

    ) and describes Alice's lucky days.

    The second line contains three integers lb

    , rb, tb (0lbrbtb1,2tb109

    ) and describes Bob's lucky days.

    It is guaranteed that both Alice and Bob have some unlucky days.

    Output

    Print one integer: the maximum number of days in the row that are lucky for both Alice and Bob.

    Examples
    Input
    Copy
    0 2 5
    1 3 5
    Output
    Copy
    2
    Input
    Copy
    0 1 3
    2 3 6
    Output
    Copy
    1
    Note

    The graphs below correspond to the two sample tests and show the lucky and unlucky days of Alice and Bob as well as the possible solutions for these tests.

    题意 : 两个人轮流会有幸运天,给你两个人的幸运天的分布情况,是按周期的,问最终重复的幸运天最多是多少?

    思路分析 :

    代码示例 :

    #define ll long long
    ll l1, r1, t1;
    ll l2, r2, t2;
    
    ll gcd(ll a, ll b){
        return b==0?a:gcd(b, a%b);
    }
    
    void solve() {
        if (l1 > l2) {swap(l1, l2); swap(r1, r2); swap(t1, t2);}
        ll len1 = r1-l1+1, len2 = r2-l2+1;
        ll g = gcd(t1, t2);
        ll ans = 0;
        ll d = (l2-l1)%g;
        ans = max(ans, min(len1-d, len2));
        ll yd = g-d;
        ans = max(ans, min(len1, len2-yd));
        printf("%lld
    ", ans);
    }
    
    int main() {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        
        cin >> l1 >> r1 >> t1;
        cin >> l2 >> r2 >> t2;
        
        solve();
        return 0;
    }
    
    东北日出西边雨 道是无情却有情
  • 相关阅读:
    新收入准则下的通用收入处理场景
    如果不先提出最佳问题,你怎么去找最佳答案呢?
    复星集团
    CFO的三重境界:阿里CFO蔡崇信教给我的那些事儿
    《让财务助推业务—业财融合》
    一、原材料、半成品、成品的采用标准成本法管理 [转发]
    顶级投行?IT->Data Analysis->Forecast->Future.
    SAP 合资公司解决方案
    SAP-关于分类账(Ledgers)的总结
    百度网盘目录树在线V2.0版功能介绍~
  • 原文地址:https://www.cnblogs.com/ccut-ry/p/9948013.html
Copyright © 2011-2022 走看看