• 【Mail.Ru Cup 2018 Round 2 C】 Lucky Days


    【链接】 我是链接,点我呀:)
    【题意】

    【题解】

    ![](https://img2018.cnblogs.com/blog/1251265/201811/1251265-20181114102634106-1195481374.png) ![](https://img2018.cnblogs.com/blog/1251265/201811/1251265-20181114102641042-105691369.png)

    题解的作者: manish_joshi

    对于任意一个k
    因为那条直线(关于x,y的方程可以看出一条直线)的斜率>=
    所以肯定会经过第一象限。
    因此总是能得到一个k1,k2>=0

    连续的1的起点尽可能接近。

    【代码】

    #include <bits/stdc++.h>
    #define LL long long
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    using namespace std;
    
    const int N = 1e5;
    
    LL la,ra,ta;
    LL lb,rb,tb;
    
    int main(){
        //freopen("D:\rush.txt","r",stdin);
        scanf("%lld%lld%lld",&la,&ra,&ta);
        scanf("%lld%lld%lld",&lb,&rb,&tb);
        if (la>lb){
            swap(la,lb);
            swap(ra,rb);
            swap(ta,tb);
        }
        //la <= lb
        /*
            st1 = la + k1*t1
            st2 = lb + k2*t2
            dif = st2-st1
                = lb-la+k2*t2-k1*t1 = 0
    
            lb-la+k2*t2=k1*t1
            t1*k1=k2*t2+lb-la
    
            dir = lb-la+k*gcd(t1,t2)
            la-lb=k*gcd(t1,t2);
            k = (la-lb)/gcd(t1,t2);
        */
        LL temp1 = la-lb;
        LL temp2 = __gcd(ta,tb);
        if (temp1%temp2==0){
            LL ans = min(rb-lb+1,ra-la+1);
            printf("%lld
    ",ans);
        }else{
            double temp = 1.0*temp1/temp2;
    
            LL len1 = ra-la+1,len2 = rb-lb+1;
            LL k = (LL) (ceil(temp));
    
            LL delta = lb-la+k*__gcd(ta,tb);
    
            LL aa = 1,bb = len1,cc = 1+delta,dd = delta+len2;
            LL ans = 0;
            ans = max(ans,min(bb,dd)-max(aa,cc)+1);
    
            k = (LL) (floor(temp));
            delta = lb-la+k*__gcd(ta,tb);
            aa = 1,bb = len1,cc = 1+delta,dd = delta+len2;
            ans = max(ans,min(bb,dd)-max(aa,cc)+1);
    
            printf("%lld
    ",ans);
        }
        return 0;
    }
    
  • 相关阅读:
    extend()和append()区别
    extend()和append()区别
    extend()和append()区别
    extend()和append()区别
    Ethtool工具源码剖析
    [数据库基础]——索引
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9956620.html
Copyright © 2020-2023  润新知