File tree Expand file tree Collapse file tree 1 file changed +88
-0
lines changed Expand file tree Collapse file tree 1 file changed +88
-0
lines changed Original file line number Diff line number Diff line change
1
+ # codeforces779 div2
2
+
3
+ ### A
4
+
5
+ > 构造,贪心
6
+
7
+ ``` cpp
8
+ void solve (){ //要想满足每个>=2的子串都满足0数目小于1,则最贪心的做法是最多填2个
9
+ int n; string s;
10
+ cin >> n >> s;
11
+ int ans = 0;
12
+ for(int i = 0; i < n; i++){
13
+ if(s[ i] == '0'){
14
+ int j = find(begin(s) + i + 1, end(s), '0') - begin(s);
15
+ if(j != n){
16
+ ans += max(0, 3 - (j - i));
17
+ i = j - 1;
18
+ }
19
+ }
20
+ }
21
+ cout << ans << endl;
22
+ }
23
+ ```
24
+
25
+
26
+
27
+ ### B
28
+
29
+ > 一眼猜答案,有一些number theory的意味在里面
30
+
31
+ 看样例猜测奇数长度不可行,然后看输出盲猜了一个规律。实际上要想满足,让所有数都%2==0即可。于是奇数在偶数下标,偶数在奇数下标,总共有((n - 2)!)^2种可能。
32
+
33
+ 详细证明:
34
+
35
+ 反证法,假设存在>2的因子,显然2 < p <= n。我们可以发现数里头被p整除的有⌊n/p⌋个,本身不被p整除的数,可以乘上p的倍数,但只有⌊n/p⌋有这样的优待,所以不满足条件;同理,p==2恰好可以
36
+
37
+ ``` cpp
38
+ void solve (){
39
+ int n;
40
+ cin >> n;
41
+ ll mod = 998244353;
42
+ if(n & 1) {
43
+ cout << 0 << endl;
44
+ return;
45
+ }
46
+ else{
47
+ //for every digits, we can check if it modulo 2 eq 0
48
+ ll ans = 1;
49
+ for(int i = 2; i <= n; i+=2){
50
+ ans *= (i / 2) * (i / 2);
51
+ ans %= mod;
52
+ }
53
+ cout << ans << endl;
54
+ }
55
+ }
56
+ ```
57
+
58
+ ### C
59
+
60
+ > constructive algorithm + number theory
61
+
62
+ 考虑每次rotate,最多可能产生影响为c[ i + 1] - c[ i] <= 1。
63
+
64
+ 显然每次rotate都可能造成上述影响
65
+
66
+ ``` cpp
67
+ void solve (){
68
+ int n;
69
+ cin >> n;
70
+ vector <int> a(n);
71
+ for(int i = 0; i < n; i++) cin >> a[i];
72
+ auto j = find(begin(a), end(a), 1);
73
+ if(j == end(a)){
74
+ cout << "NO\n";
75
+ return;
76
+ }
77
+ rotate (begin (a), j, end(a));
78
+ for(int i = 1; i < n; i++){
79
+ if(a[ i] - a[ i - 1] > 1 || a[ i] == 1){
80
+ cout << "NO\n";
81
+ return;
82
+ }
83
+ }
84
+ cout << "YES\n";
85
+ }
86
+ ```
87
+
88
+
You can’t perform that action at this time.
0 commit comments