Educational Codeforces Round 59 Solution

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 }

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 }

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 }

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 }

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

时间: 2024-08-30 14:38:19

Educational Codeforces Round 59 Solution的相关文章

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Educational Codeforces Round 57 Solution

A. Find Divisible 签到. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int t, l, r; 5 6 int main() 7 { 8 scanf("%d", &t); 9 while (t--) 10 { 11 scanf("%d%d", &l, &r); 12 printf("%d %d\n", l, l * 2); 13

Educational Codeforces Round 59 (Rated for Div. 2) E 区间dp + 状态定义

https://codeforces.com/contest/1107/problem/E 题意 给出01字符串s(n<=100),相邻且相同的字符可以同时消去,一次性消去i个字符的分数是\(a[i]\),问消去s最多能得到多少分数 题解 实质是安排消去次序使得分数最大,第一步采取的行动是递归边界 因为只有01串,所以s被分成了一段一段,考虑段处理 预处理出一次性消去i个字符的最大分数\(f[i]\) 定义\(dp[l][r][cnt]\)为消去第l到第r段加上cnt个字符和第l段相同得到的最大

Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下后面一定是对的因为按照数字大小 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n;

Educational Codeforces Round 59 (Rated for Div. 2)

A.Digits Sequence Dividing 题意:给你一个1-9的数字字符串,把它划分成若干段(>=2)段,使其大小递增. 错误:当长度为2的时候没考虑 #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<map> using

Educational Codeforces Round 59 (Rated for Div. 2)(ABCD)

A. Digits Sequence Dividing 题意:给你一个数字串,只包含1-9,让你至少分成两段,使得每一段的数字大于前一段的数字: 解:对n特判,如果n为2,那么比较一下两个数字大小,如果n>2,那么就可以直接分成两部分,第一部分1个数字,剩下都为第二部分: #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e3+10; const int mod=9982

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,