A. Roman and Browser

签到.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n, k, a[110];
 5 
 6 int get(int b)
 7 {
 8     int vis[110];
 9     memset(vis, 0, sizeof vis);
10     int c = b; 
11     while (c <= n)
12     {
13         vis[c] = 1;
14         c += k;
15     }
16     c = b - k;
17     while (c >= 1)
18     {
19         vis[c] = 1;
20         c -= k;
21     }
22     int l = 0, r = 0;
23     for (int i = 1; i <= n; ++i) if (!vis[i])
24     {
25         if (a[i] == 1) ++l;
26         else ++r;
27     }
28     return abs(l - r);
29 }
30 
31 int main()
32 {
33     while (scanf("%d%d", &n, &k) != EOF)
34     {
35         for (int i = 1; i <= n; ++i) scanf("%d", a + i);
36         int res = 0;
37         for (int i = 1; i <= n; ++i) res = max(res, get(i));
38         printf("%d\n", res);
39     }
40     return 0;
41 }
View Code

相关文章:

  • 2021-12-06
  • 2022-01-13
  • 2021-05-23
  • 2021-05-18
  • 2021-10-04
  • 2022-02-20
  • 2022-12-23
  • 2021-05-23
猜你喜欢
  • 2021-12-06
  • 2021-05-31
  • 2021-08-19
  • 2022-02-11
  • 2021-09-29
  • 2021-09-30
  • 2021-06-15
相关资源
相似解决方案