zoukankan      html  css  js  c++  java
  • [Luogu 1516] 青蛙的约会

    [Luogu 1516] 青蛙的约会

    <题目链接>


    两年前和初中那群队友一起当模拟做过,一起 TLE,一起骂过的题目;

    一年前队友的博客上被当作例题,被我抄下来去操场都带着看的题目;

    终于好好学习了 ExGCD,才发现是扩欧板子题并顺手切掉的题目…

    雨中灯市欲眠,原已萧萧数年。
    似有故人轻叩,又将旧题重写。
    能否消得你一路而来的半生风雪?

    #include <cstdio>
    #include <cstdlib>
    
    long long a, b, c, x, y, ans; 
    
    void Read(void)
    {
        long long x, y, m, n; 
        scanf("%lld %lld %lld %lld %lld", &x, &y, &m, &n, &b); 
        a = n - m; 
        c = x - y; 
        if(a < 0)
        {
            a = -a; 
            c = -c; 
        }
    }
    
    long long ExGCD(long long a, long long b, long long& x, long long& y)
    {
        if(!b)
        {
            x = 1; 
            y = 0; 
            return a; 
        }
        long long t = ExGCD(b, a % b, y, x); 
        y -= a / b * x; 
        return t; 
    }
    
    int main(void)
    {
        Read(); 
        ans = ExGCD(a, b, x, y); 
        if(c % ans)
            puts("Impossible"); 
        else
            printf("%lld
    ", ((x * c / ans) % (b / ans) + (b / ans)) % (b / ans)); 
        return 0; 
    }
    

    谢谢阅读。

  • 相关阅读:
    Palindrome Partitioning
    Minimum Path Sum
    Maximum Depth of Binary Tree
    Minimum Depth of Binary Tree
    Unique Binary Search Trees II
    Unique Binary Search Trees
    Merge Intervals
    Merge Sorted Array
    Unique Paths II
    C++ Primer Plus 笔记第九章
  • 原文地址:https://www.cnblogs.com/Capella/p/9852791.html
Copyright © 2011-2022 走看看