Comet OJ - Contest # 7 solving report

Portal: https://www.cometoj.com/contest/52


A: attendance problem

The meaning of problems: asked many times, each time a given interrogation range interval [l, r], the interval range selected from two integers (repeated) to sequentially obtain "least common multiple of the maximum" maybe number "least common multiple of the smallest," "the greatest common divisor", the smallest common divisor.

Analysis: (1) Obviously, when the interval length of 1, the answer to this question can only be the only zone that number.

   (2) When the length of the interval is greater than 1, the maximum of the least common multiple, LCM max = LCM (A R & lt , A R & lt-1 ) A = R & lt * A R & lt-1;

                The smallest least common multiple, LCM min = LCM (A L , A L ) = A L;

                The largest common divisor, GCD max = GCD (A R & lt , A R & lt ) A = R & lt;

                Smallest common divisor, GCD min = GCD (A R & lt , A R & lt-. 1 ) =. 1;

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main() {
 6     int t;
 7     scanf("%d",&t);
 8     while (t--) {
 9         int l,r;
10         scanf("%d%d",&l,&r);
11 
12         if (l == r) {
13             printf("%d %d %d %d\n",l,l,l,l);
14         } else {
15             printf("%lld %d %d %d\n",(long long)r*(r-1),l,r,1);
16         }
17     }
18 
19     return 0;
20 }
View Code

B: Mahjong title

The meaning of problems: 4 individuals (numbered 1 to 4) surrounded by a ring, two adjacent positions can be exchanged. Now given in counterclockwise order number on the ring, on behalf of 4 positional relationship table. Minimum requirements need to exchange position many times in order to meet the next element 1 is the next element is the next element 2,2 3,3 4,4 is the next element is 1.

Analysis: Since only four elements on the ring, switching frequency up to no more than two times, so we can consider direct enumeration situation.

   (1) If this sequence start condition is satisfied, 0 is the least number of exchanges.

   (2) If this sequence is the positional relationship (1,4,3,2), a minimum number of exchanges 2.

   (3) the remaining cases the minimum number of exchanges are 1.

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main() {
 6     int num[4],pos = 0;
 7     for (int i=0;i<4;i++) {
 8         scanf("%d",&num[i]);
 9         if (num[i] == 1)
10             pos = i;
11     }
12 
13     int arr[4];
14     int pick[4] = {1,4,3,2};
15     bool two = true;
16     for (int i = 0;i<4;i++) {
17         arr[i] = num[pos];
18         pos = (pos + 1)%4;
19         if (arr[i] != pick[i]) {
20             two = false;
21         }
22     }
23 
24     if (two) {
25         puts("2");
26     } else {
27         int i = 1;
28         for (;i<4;i++) {
29             if (arr[i] != arr[i-1] + 1) {
30                 break;
31             }
32         }
33         if (i == 4) {
34             puts("0");
35         } else {
36             puts("1");
37         }
38     }
39 
40     return 0;
41 }
View Code

 

Guess you like

Origin www.cnblogs.com/doublebit/p/11348040.html