Round Corridor CodeForces - 1200C(最大公因数)

题目链接:https://codeforces.com/contest/1200/problem/C

思路:两个方块能互相到达的条件是,内圈的墙与外圈的墙在一条线上的区域内。每个区域内的外圈方块数与内圈方块数是相同的。

发现每个区域内圈方块数等于总内圈方块数除以总内圈方块数与外圈方块数的最大公因数,每个区域的外圈方块数也是这样。

然后看两个方块是否在同一区域即可

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <queue>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <map>
 8 #define mem(a,b) memset(a,b,sizeof(a));
 9 using namespace std;
10 #define INF 0x3f3f3f3f
11 typedef long long ll;
12 int dir[4][2] = {0,1,0,-1,1,0,-1,0};
13 const int maxn = 100005;
14 int main()
15 {
16     ll n,m,g,g1,g2;
17     int q;
18     cin >> n >> m >> q;
19     g = __gcd(n,m);
20     g1 = n / g, g2 = m / g;
21     while(q--)
22     {
23         ll x1,y1,x2,y2;
24         cin >> x1 >> y1 >> x2 >> y2;
25         if(x1 == 1&&x2 == 2)
26         {
27             if((y1-1)/g1 == (y2-1)/g2)
28                 cout << "YES" << endl;
29             else
30                 cout << "NO" << endl;
31         }
32         else if(x1 == 1&&x2 == 1)
33         {
34             if((y1-1)/g1 == (y2-1)/g1)
35                 cout << "YES" << endl;
36             else
37                 cout << "NO" << endl;
38         }
39         else if(x1 == 2&&x2 == 1)
40         {
41             if((y1-1)/g2 == (y2-1)/g1)
42                 cout << "YES" << endl;
43             else
44                 cout << "NO" << endl;
45         }
46         else if(x1 == 2&&x2 == 2)
47         {
48             if((y1-1)/g2 == (y2-1)/g2)
49                 cout << "YES" << endl;
50             else
51                 cout << "NO" << endl;
52         }
53     }
54     return 0;
55 }

 

posted on 2019-08-16 09:27  一只小毛球  阅读(305)  评论(0编辑  收藏  举报

导航