link

 

前几天补完了某一场很早以前的div1,突然想来更博客,于是就有了这篇文章

 

A The Beatles

显然若起点和第一次到达的位置距离为 d ,那么经过的不同站点数为 $\frac{nk}{\gcd(d,nk)}$ 。

假设距离起点最近的快餐店是 1 ,枚举距离第一次到达的位置最近的快餐店是多少, $2^2$ 枚举起点和终点在左还是右,更新答案即可。

 1 #include<bits/stdc++.h>
 2 #define rep(i,x,y) for (int i=(x);i<=(y);i++)
 3 #define ll long long
 4 
 5 using namespace std;
 6 
 7 const int N=1e5+10;
 8 int n,m,a,b; ll len,ans1,ans2;
 9 
10 ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
11 inline ll get(ll x){
12     x<=0?x+=len:0;
13     x>len?x-=len:0;
14     return x;
15 }
16 inline void upd(ll x){
17     x=len/gcd(len,x);
18     ans1=min(ans1,x),ans2=max(ans2,x);
19 }
20 inline void chk(ll x,ll y){
21     if (x>y) swap(x,y);
22     upd(y-x),upd(x+len-y);
23 }
24 
25 int main(){
26     scanf("%d%d%d%d",&n,&m,&a,&b); len=(ll)n*m;
27     ans1=len+1,ans2=0;
28     ll q=1;
29     rep (i,1,n){
30         ll p=(ll)(i-1)*m+1;
31         ll x=get(p-a),y=get(q-b); chk(x,y);
32         x=get(p-a),y=get(q+b); chk(x,y);
33         x=get(p+a),y=get(q-b); chk(x,y);
34         x=get(p+a),y=get(q+b); chk(x,y);
35     }
36     printf("%lld %lld\n",ans1,ans2);
37     return 0;
38 }
View Code

相关文章:

  • 2022-12-23
  • 2022-02-27
  • 2021-06-25
  • 2021-08-21
  • 2021-11-27
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2021-12-10
  • 2021-12-03
  • 2021-08-17
  • 2021-05-21
  • 2021-06-27
相关资源
相似解决方案