数学杂题

一句话口胡数学题系列

还是我太弱了

摆在这留给老(tui)了(yi)的时候看吧

1,洛谷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

2,[JSOI2009]瓶子和燃料

 给你$n$个有容量的瓶子 , 从中取出$k$个 , 使得取出的瓶子所能表达出的最小体积最大

根据裴蜀定理 , $k$个瓶子所可表达出的最小体积是其$Gcd$

找出$n$个桶子的因子出现次数 , 去最大的出现次数大于等于$k$的记为答案

$map$储存即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <map>
 6 #include <cmath>
 7 #define inc(i) (++ (i))
 8 #define dec(i) (-- (i))
 9 using namespace std;
10 
11 const int N = 1000 + 7;
12 int n , k , A , Ans;
13 map <int , int> M;
14 
15 int main()
16 {
17     scanf("%d%d" , &n , &k);
18     for(int i = 1 ; i <= n ; inc(i))
19     {
20         scanf("%d" , &A);
21         for(int j = 1 , Max = sqrt(A) ; j <= Max ; inc(j))
22             if(A % j == 0)
23             {
24                 inc(M[j]) , inc(M[A / j]);
25                 if(M[j] >= k) Ans = max(Ans , j);
26                 if(M[A / j] >= k) Ans = max(Ans , A / j);
27             }
28     }
29     printf("%d" , Ans);
30     return 0;
31 }
JSOI2009

猜你喜欢

转载自www.cnblogs.com/Shine-Sky/p/9452001.html