标签:包括 单位 长度 math clu mat tmp inpu max
1 2 3 4 5
4
我们容易列出方程:
$m*t-n*t=k*l+y-x$,其中$t$表示时刻,$k$表示走过$k$圈。
我们提出$t$,$k$:$(m-n)*t-l*k=y-x$。
用$exgcd$求出一组解后,再找到t的最小正整数解。
1 //It is made by Awson on 2017.10.7 2 #include <map> 3 #include <set> 4 #include <cmath> 5 #include <ctime> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <cstdio> 10 #include <string> 11 #include <cstdlib> 12 #include <cstring> 13 #include <iostream> 14 #include <algorithm> 15 #define LL long long 16 #define Max(a, b) ((a) > (b) ? (a) : (b)) 17 #define Min(a, b) ((a) < (b) ? (a) : (b)) 18 using namespace std; 19 20 LL x, y, m, n, l; 21 22 LL exgcd(LL a, LL b, LL &x, LL &y) { 23 if (b == 0) { 24 x = 1; y = 0; 25 return a; 26 } 27 LL c = exgcd(b, a%b, x, y); 28 LL t = x; 29 x = y; 30 y = t-a/b*y; 31 return c; 32 } 33 void work() { 34 scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &l); 35 LL ta = m-n, tb = l, tc = y-x, t, k; 36 LL gcd = exgcd(ta, tb, t, k); 37 if (tc%gcd) printf("Impossible\n"); 38 else { 39 t *= tc/gcd; 40 LL tmp = tb/gcd; 41 if (tmp < 0) tmp = -tmp; 42 printf("%lld\n", (t%tmp+tmp)%tmp); 43 } 44 } 45 int main() { 46 work(); 47 return 0; 48 }
标签:包括 单位 长度 math clu mat tmp inpu max
原文地址:http://www.cnblogs.com/NaVi-Awson/p/7634880.html