Codeforces Round #575 (Div. 3)

Hang power play and more play autistic school, stay up all night playing games cf find confidence.

Topic is water, that is the question face long and boring.

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


A:

See seems very complicated, a look at the sample, the answer is just three numbers add up except 2.

 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 q;
21 
22 int main() {
23     cin >> q;
24     while (q--) {
25         ll sum = 0, a, b, c; cin >> a >> b >> c;
26         sum = (a + b + c) / 2;
27         cout << sum << endl;
28     }
29     return 0;
30 }
View Code

B:

Prefix and maintenance intervals parity, then find and greed for the interval to odd, because certain intervals and is even talk to merge adjacent odd intervals.

 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 = 2e5 + 10;
21 // const int maxn = 10;
22 int q, a[maxn];
23 vector<int>ans;
24 
25 int main() {
26     scanf("%d", &q);
27     while (q--) {
28         int n, k;
29         ans.clear();
30         scanf("%d%d", &n, &k);
31         rep1(i, 1, n) {
32             int x; scanf("%d", &x);
33             if (x & 1) a[i] = 1; else a[i] = 0;
34             a[i] += a[i - 1];
35         }
36         int re = k, flag = 1, lastPos = 0;
37         rep1(i, 1, n) {
38             if (re == 1)
39                 if ((a[n] - a[i - 1]) % 2) {
40                     re--; ans.pb(n); break;
41                 } else {
42                     flag = 0; break;
43                 }
44             if ((a[i] - a[lastPos]) % 2) {
45                 re--;
46                 ans.pb(i);
47                 lastPos = i;
48             }
49         }
50         if (flag && !re) {
51             // have solution
52             puts("YES");
53             for (auto i : ans) printf("%d ", i);
54             puts("");
55         } else puts("NO");
56     }
57     return 0;
58 }
View Code

C:

Maintenance answers range of x and y may arise, the final check is legitimate can be.

 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 main() {
21     int q;
22     scanf("%d", &q);
23     while (q--) {
24         int n, xl = -100000, xr = 100000, yu = 100000, yd = -100000;
25         scanf("%d", &n);
26         rep1(i, 1, n) {
27             int x, y, f1, f2, f3, f4; scanf("%d%d%d%d%d%d", &x, &y, &f1, &f2, &f3, &f4); //zuo shang you xia
28             if (f1 + f2 + f3 + f4 == 4) continue;
29             if (!f1) xl = max(xl, x);
30             if (!f2) yu = min(yu, y);
31             if (!f3) xr = min(xr, x);
32             if (!f4) yd = max(yd, y);
33         }
34         // ans
35         if (xl <= xr && yu >= yd) printf("1 %d %d\n", xl, yd);
36         else puts("0");
37     }
38     return 0;
39 }
View Code

D1:

Nothing to say, is violence.

 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 = 2e3 + 10;
21 char s[maxn];
22 map<char, char>m;
23 
24 int main() {
25     m['R'] = 'G'; m['G'] = 'B'; m['B'] = 'R';
26     int q; scanf("%d", &q);
27     while (q--) {
28         int n, k, ans = int_inf; scanf("%d%d", &n, &k);
29         scanf("%s", s + 1);
30         for (int i = 1; i + k - 1 <= n; i++) {
31             char curr = 'R'; int cnt = 0;
32             rep1(j, i, i + k - 1) {
33                 if (s[j] != m[curr]) cnt++;
34                 curr = m[curr];
35             }
36             ans = min(ans, cnt);
37             curr = 'G'; cnt = 0;
38             rep1(j, i, i + k - 1) {
39                  if (s [j] = m [curr]!) Cnt ++ ;
40                  curr = m [curr];
41              }
 42              years = min (years cnt);
43              curr = ' B ' ; cnt = 0 ;
44              dir1 (j, i, i + k - 1 ) {
 45                  if (s [j] = m [curr]!) Cnt ++ ;
46                  curr = m [curr];
47              }
 48              years = min (years cnt);
49          }
 50          printf (" % D \ n " , year);
51      }
 52      return  0 ;
53 }
View Code

D2:

dp。

 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 = 2e5 + 10;
21 const string rgb = "RGB";
22 int q, n, k, dp[maxn];
23 char s[maxn];
24 
25 int solve(int x) {
26     rep1(i, 1, n) {
27         dp[i] = dp[i - 1] + (rgb[x] != s[i]);
28         x = (x + 1) % 3;
29     }
30     int ret = dp[k];
31     for (int i = k + 1; i <= n; i++)
32         ret = min(ret, dp[i] - dp[i - k]);
33     return ret;
34 }
35 
36 int main() {
37     scanf("%d", &q);
38     while (q--) {
39         scanf("%d%d", &n, &k);
40         scanf("%s", s + 1);
41         int ans = min(min(solve(0), solve(1)), solve(2));
42         printf("%d\n", ans);
43     }
44     return 0;
45 }
View Code

E && F:

Is said to be bare questions, do not be completed.

 

Guess you like

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