Codeforces Round #562 (div.2)

Before AtCoder BC 128 with the same title at night, did not play.

This question face very short, praise.

Topic links: https://codeforces.com/contest/1169


A:

Title long and stinking, the result is a mentally handicapped simulation.

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson curPos<<1
15 #define rson curPos<<1|1
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 int n, a, x, b, y;
21 
22 int main() {
23     cin >> n >> a >> x >> b >> y;
24     while ((a != x) && (b != y)) {
25         a = a == n ? 1 : a + 1;
26         b = b == 1 ? n : b - 1;
27         if (a == b) return puts("YES"), 0;
28     }
29     puts("NO");
30     return 0;
31 }
View Code

B:

It is also mentally retarded.

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson curPos<<1
15 #define rson curPos<<1|1
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 3e5 + 10;
21 int n, m, cnt[maxn];
22 vector<pair<int, int>>v;
23 
24 int check(int x) {
25     rep0(i, 0, maxn) cnt[i] = 0;
26     int s = 0;
27     rep0(i, 0, m)
28     if (v[i].first != x && v[i].second != x) {
29         cnt[v[i].first]++, cnt[v[i].second]++;
30         s++;
31     }
32     rep1(i, 1, n)
33     if (cnt[i] == s)
34         return 1;
35     return 0;
36 }
37 
38 int main() {
39     scanf("%d%d", &n, &m);
40     rep1(i, 1, m) {
41         int x, y; scanf("%d%d", &x, &y);
42         v.pb(mp(x, y));
43     }
44     if (check((*v.begin()).first) || check((*v.begin()).second))
45         puts("YES");
46     else puts("NO");
47     return 0;
48 }
View Code

C:

Given n, m and the number n, each number range is [0, m). And there is only one operation: each operation can select any number k, for each number of a [i], a [i] = (a [i] +1)% m. I asked a minimum of several operations that do not fall into a number of columns in the original series.

Data range 3e5, a look that is half the problem.

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson curPos<<1
15 #define rson curPos<<1|1
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 3e5 + 10;
21 int n, m, a[maxn];
22 
23 int main() {
24     scanf("%d%d", &n, &m);
25     rep0(i, 0, n) scanf("%d", &a[i]);
26     int l = -1, r = m;
27     while (l < r - 1) {
28         int mid = l + r >> 1, prev = 0, flag = 1;
29         rep0(i, 0, n) {
30             int lpos = a[i], rpos = a[i] + mid;
31             if ((lpos <= prev && prev <= rpos) || (lpos <= prev + m && prev + m <= rpos))
32                 continue;
33             if (a[i] > prev) prev = a[i];
34             else {
35                 flag = 0;
36                 break;
37             }
38         }
39         if (flag) r = mid; else l = mid;
40     }
41     printf("%d\n", r);
42     return 0;
43 }
View Code

D:

Given a length n of 01 string s, find the number of L, R & lt ( . 1 L R & lt n), the presence of at least one pair of x, k, satisfies . 1 X , K n, L X < X + 2 K R & lt, and S [ X] = S [ X + K] = S [ X + 2 K].

Translation of what is the number of sections, there is at least a triple (a, b, c) interval, a == b == c and equally spaced.

Violence, pieces get away.

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson curPos<<1
15 #define rson curPos<<1|1
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 3e5 + 10;
21 int a[maxn];
22 string s;
23 ll ans = 0;
24 
25 int main() {
26     cin >> s;
27     int len = s.size();
28     rep0(i, 0, maxn) a[i] = int_inf;
29     rep0(i, 0, len) {
30         for (int j = 1; i + 2 * j < len; j++)
31             if (s[i] == s[i + j] && s[i] == s[i + 2 * j]) {
32                 a[i] = i + 2 * j;
33                 break;
34             }
35     }
36     for (int i = len - 1; i >= 0; i--) a[i] = min(a[i], a[i + 1]);
37     rep0(i, 0, len)
38     if (a[i] != int_inf) ans += len - a[i];
39     printf("%lld\n", ans);
40     return 0;
41 }
View Code

E:

To be completed.

 

Guess you like

Origin www.cnblogs.com/JHSeng/p/10936442.html