POJ

来源:互联网 发布:淘宝穿过的鞋子退货 编辑:程序博客网 时间:2024/06/05 07:44

本来以为很水,两个蛙蛙之间正向逆向距离 除 速度差就好了,但是不对,还得考虑他们转过好多圈以后 (多少圈不确定,解方程呗)

输入 x, y, m, n, r   =>  假设他们走了 i 步, 转了 j 圈  ==>  m*i - n*i =   (x - y)+ r * j ; ==>  (m-n) * i  +  r * j  =  (x - y)

#include<iostream>#include<cstdio>using namespace std;typedef long long LL;LL x, y, m, n, r, d;void find_(LL a, LL b, LL &g, LL &x, LL &y) {    if(!b) { g = a; x = 1; y = 0; return; }    find_(b, a%b, g, y, x);    y -= (a/b) * x;}int main() {    //cout << -1%1 << endl;    scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &r);    LL x_, y_;    find_(n-m, r, d, x_, y_);    //cout << d << endl;    if((x-y) % d) { cout << "Impossible" << endl; return 0; }    x_ *= (x-y)/d;    LL t = r / d;    x_ = ( x_%t + t ) % t;    cout << x_ ;    return 0;}


原创粉丝点击