Codeforces Round #562 (Div. 2) A题 Circle Metro

Topic links: codeforces.com/contest/1169/problem/A

 

 

 Meaning of the questions: There are two metro, from a 1 → 2 → ... → n → 1 → 2 → ..., from a n → n-1 → ... → 1 → n → n-1 → .... Metro also open the elapsed time and the subway station are the same, two people sit in front of it a two, a two sit behind that, you give them a starting point and terminus, ask if they have this possibility in the course of a station at the same time , might output YES, otherwise output NO.

Ideas: adding a start from the beginning i a, j a start subtracted from b, n + 1 if i is added to let it return to 1, j is reduced to 0 to return to his n, j if i == described in the same station . I or j if one of the parties to reach the terminal x or y, then it ends.

AC Code:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<string>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,a,b,x,y;
 8     while(cin >> n >> a >> x >> b >> y)
 9     {
10         bool flag = false;
11         for(int i = a,j = b;;i++,j--)
12         {
13             if(i == n + 1) i = 1;
14             if(j == 0) j = n;
15             if(i == j)
16             {
17                 flag = true;break;
18             }
19             if(i == x ||  j == y) break;
20         }
21         if(flag) cout << "YES" << endl;
22         else cout << "NO" << endl;
23     }
24     return 0;
25 }

 

Guess you like

Origin www.cnblogs.com/Carered/p/10930015.html