码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 59 Solution

时间:2019-01-27 10:49:41      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:eof   dig   reverse   eset   view   hang   begin   sed   运算   

 

A. Digits Sequence Dividing

签.

技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 1010
 5 char s[N]; int n; 
 6 
 7 void solve()
 8 {
 9     if (n == 2 && s[1] >= s[2]) 
10     {
11         puts("NO"); 
12         return;
13     }
14     else
15     {
16         puts("YES");
17         puts("2");
18         printf("%c %s\n", s[1], s + 2);
19     }
20 }
21 
22 int main()
23 {
24     int t; scanf("%d", &t);
25     while (t--)
26     {
27         scanf("%d", &n);
28         scanf("%s", s + 1);
29         solve();
30     }
31     return 0;
32 }
View Code

 

 

B. Digital root

签.

技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define ll long long
 5 int t;
 6 ll k, x;
 7 
 8 int main()
 9 {
10     scanf("%d", &t);
11     while (t--)
12     {
13         scanf("%lld%lld", &k, &x);
14         printf("%lld\n", (k - 1) * 9 + x);
15     }
16     return 0;
17 }
View Code

 

 

C. Brutality

每次连续的一段中如果大于$k个,取最大的k个$

技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define ll long long
 5 #define N 200010
 6 int n, k;
 7 ll a[N];
 8 char s[N];
 9 
10 int main()
11 {
12     while (scanf("%d%d", &n, &k) != EOF)
13     {
14         for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
15         scanf("%s", s + 1); s[n + 1] = #;
16         priority_queue <ll> pq; pq.push(a[1]);
17         ll res = 0;
18         for (int i = 2; i <= n + 1; ++i)
19         {
20             if (s[i] != s[i - 1]) 
21             {
22                 for (int j = k; !pq.empty() && j; --j)
23                 {
24                     res += pq.top(); pq.pop();
25                 }
26                 while (!pq.empty()) pq.pop();
27             }
28             pq.push(a[i]);
29         }
30         printf("%lld\n", res);
31     }
32     return 0;
33 }
View Code

 

 

D. Compression

Solved.

题意:

有$n \cdot n的01矩阵,把矩阵压缩,压缩后的大小为\frac {n}{x}$ 

思路:

考虑$x | n, 枚举n的因数,在5200范围下,最多有60个$

$然后每次枚举因数n^2判断是否可以 就可以喜提TLE一枚$

$我们考虑用bitset优化$

$我们先处理出b数组第一行,然后接下来x - 1行都可以直接位运算赋值$

$那么这个复杂度就是O(\frac{n^2}{64} + (\frac{n^2}{x}))$

我们发现$< x 的因数不会太多 当因数 > x 的时候 复杂度就接近O(\frac{n^2}{64})$

$然后和a数字异或可以O(\frac{n^2}{64}) 判断合法性$

技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 5510
 5 int n;
 6 bitset <N> a[N], b[N], tmp;  
 7 char s[N][N];
 8 char Hash[210]; 
 9 int res; 
10 
11 void change(int x)
12 {
13     a[x].reset();
14     for (int i = 1, j = 0; i <= n / 4; ++i)
15     {
16         int num = Hash[s[x][i]];
17         for (int k = 3; k >= 0; --k)
18             a[x][++j] = (num >> k) & 1;
19     }
20 }
21 
22 bool solve(int x)
23 {
24     for (int i = 1; i <= n; i += x)
25     {
26         tmp.reset();
27         for (int j = 1; j <= n; j += x)
28             for (int k = j; k < j + x; ++k)
29                 tmp[k] = a[i][j];
30         for (int j = i; j < i + x; ++j) 
31         {
32             b[j] &= 0; 
33             b[j] |= tmp;
34         }
35     } 
36     for (int i = 1; i <= n; ++i) if ((a[i] ^ b[i]) != 0)  
37     {
38         return false;
39     }
40     return true;
41 }
42 
43 int main()
44 {
45     for (int i = 0; i <= 9; ++i) Hash[i + 0] = i;
46     Hash[A] = 10;
47     Hash[B] = 11;
48     Hash[C] = 12;
49     Hash[D] = 13; 
50     Hash[E] = 14;
51     Hash[F] = 15;
52     while (scanf("%d", &n) != EOF)
53     {
54         for (int i = 1; i <= n; ++i)
55             scanf("%s", s[i] + 1);    
56         for (int i = 1; i <= n; ++i) change(i); 
57         res = 1; 
58         vector <int> fac;
59         for (int i = 1; i * i <= n; ++i) if (n % i == 0) fac.push_back(i), fac.push_back(n / i);  
60         sort(fac.begin(), fac.end());
61         fac.erase(unique(fac.begin(), fac.end()), fac.end());
62         reverse(fac.begin(), fac.end()); 
63         for (auto it : fac) if (it > 1)
64         {
65             if (solve(it)) 
66             {
67                 res = it;
68                 break;
69             }
70         }
71         printf("%d\n", res); 
72     }
73     return 0;
74 }
View Code

 

Educational Codeforces Round 59 Solution

标签:eof   dig   reverse   eset   view   hang   begin   sed   运算   

原文地址:https://www.cnblogs.com/Dup4/p/10325551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!