洛谷1516 青蛙的約會

傳送機

青蛙有$GF$而我沒有系列。設青蛙$A$的出發點座標是$x$,青蛙$B$的出發點座標是$y$。青蛙$A$一次能跳$m$米,青蛙$B$一次能跳$n$米,兩隻青蛙跳一次所花費的時間相同。緯度線總長$L$米。現在要你求出它們跳了幾次以後纔會碰面。

 

設最終移動$a$步 , $A$比$B$多移動$b$(可負)圈

$x + am + bl = y + an$

$a(m - n) + bl = y - x$

拓歐即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define inc(i) (++ (i))
 6 #define dec(i) (-- (i))
 7 #define int long long
 8 using namespace std;
 9 
10 
11 inline void ExGcd(int a , int b , int& x , int& y , int &d)
12 {
13     if(b == 0)
14     {
15         x = 1 , y = 0 , d = a;
16         return;
17     }
18     ExGcd(b , a % b , y , x , d);
19     y -= a / b * x;
20 }
21 
22 int a , b , c , d , X , Y , m , n , L;
23 
24 signed main()
25 {
26     scanf("%lld%lld%lld%lld%lld" , &X , &Y , &m , &n , &L);
27     if(n > m) swap(n , m) , swap(X , Y);
28     c = Y - X;
29     ExGcd(m - n , L , a , b , d);
30     if(c % d)
31     {
32         puts("Impossible");
33         return 0;
34     }
35     a = (a + L) % L * (c + L) % L / d;
36     printf("%lld" , a);
37     return 0;
38 }
luogu1516

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章