zoukankan      html  css  js  c++  java
  • POJ1061 青蛙的约会

    奇葩的是我居然用不了abs去得到longlong的绝对值,于是自己写了一个...

    扩展欧几里得即可解决了。

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<string>
    #include<set>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<list>
    #include<cstring>
    #include<map>
    #include<stack>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define maxn 1005
    #define ull unsigned long long
    #define ll long long
    #define hashmod 99999839
    #define mod 9997
    long long x,y,m,n,l;
    long long lllabs(long long x){
        return (x < 0) ? -x : x;
    }
    long long exgcd(long long a,long long b,long long& x,long long& y){
        if(!b){x=1ll,y=0ll;return a;}
        ll g = exgcd(b,a%b,x,y);
        ll t = x;
        x = y;
        y = t - a/b*y;
        return g;
    }
    void solve(){
        long long A = m - n,B = l,C = y-x;
        long long tx,ty;
        long long g = exgcd(lllabs(A),lllabs(B),tx,ty);//AX+BY=C
        if(C % g != 0){
            puts("Impossible");
            return;
        }
        if(A < 0) tx = -tx;
        B /= g;
        tx = tx * (C / g);//AX + BY = C
        tx = tx + (lllabs(tx)/B+1ll)*B;
        tx %= B;
        printf("%lld
    ",tx);
    }
    int main(){
      //  freopen("a.in","r",stdin);
      //  freopen("b.out","w",stdout);
        while(~scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)){
            solve();
        }
        return 0;
    }
  • 相关阅读:
    Gamma阶段第三次scrum meeting
    【技术博客】Django+uginx+uwsgi框架的服务器部署
    Gamma阶段第二次scrum meeting
    Gamma阶段第一次scrum meeting
    团队项目贡献分
    Beta阶段发布说明
    Beta阶段测试报告
    【Beta阶段】第十次Scrum Meeting
    团队贡献分汇总
    [Gamma]Scrum Meeting#4
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9523161.html
Copyright © 2011-2022 走看看