Educational Codeforces Round 179 (Rated for Div. 2) 补题

A. Energy Crystals

题没看懂,直接 guess 的样例。

输出二进制最高位 * 2 + 1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=1e9+7;

int n;

void solve(){
    cin>>n;
    for(int i=0;i<=64;i++) {
        ll tmp = (1ll<<i);
        if(tmp > n) {
            cout << i*2+1 <<endl;
            return;
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

B. Fibonacci Cubes

这堆方块放在一起,底部是第 n 块正方体,高度是最大和第二大的叠一起,只要这个高度和底部能放下即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=1e9+7;

int n,m,f[20];
int a[3];

void solve(){
    cin>>n>>m;
    int t1=f[n], t2=f[n+1];
    vector<int> ans;
    for(int i=0;i<m;i++){
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if(a[0] >= t1 && a[1] >= t1 && a[2] >= t2){
            ans.push_back(1);
        } else ans.push_back(0);
    }
    for(auto x:ans) cout<<x;
    cout<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    f[0]=f[1]=1;
    for(int i=2;i<20;i++) f[i]=f[i-1]+f[i-2];
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

C. Equal Values

计算没开 ll 白吃两发 wa

操作肯定是左右各来一次,确定执行位置即可,相同数字归为一个片段,操作在片段两侧进行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=5e5+7, mod=1e9+7;

struct Node{
    ll val,l,r;
};

ll n,a[N];

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    vector<Node>t;
    Node lst={0,0,0};
    t.push_back(lst);
    int tot=0;
    for(int i=1;i<=n;i++){
        if(a[i]==t[tot].val){
            t[tot].r++;
        }else{
            t.push_back({a[i],i,i});
            tot++;
        }
    }
    ll ans=1e18;
    for(int i=1;i<=tot;i++){
        ll l=t[i].l, r=t[i].r, v=t[i].val;
        ll tmp=(l-1)*v+(n-r)*v;
        ans=min(ans,tmp);
    }   
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

D. Creating a Schedule

相邻位置为一组,二者要一高一低。

每组人只上两节课即可,从两侧向中间,依次分配。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


struct Node {
    int f; 
    ll id; 
};

bool cmp(Node a, Node b){
    return a.f < b.f; 
};

void solve() {
    int n, m;                     
    cin >> n >> m;
    vector<Node> E, O;                
    for (int i = 0; i < m; ++i) {
        ll x; cin >> x;
        int fl = int(x / 100);     
        E.push_back({fl, x});     
        O.push_back({fl, x});      
    }
    sort(E.begin(), E.end(), cmp);
    sort(O.begin(), O.end(), cmp);

    int lE = 0, rE = m - 1, lO = 0, rO = m - 1;
    vector<pair<Node,Node>> g(n);       

    for (int i = 0; i < n; ++i) {
        int d1 = O[rO].f - E[lE].f;
        int d2 = E[rE].f - O[lO].f;
        if (d1 >= d2) {            
            g[i] = {E[lE++], O[rO--]};      
        } else {
            g[i] = {E[rE--], O[lO++]};      
        }
    }

   
    for (int i = 0; i < n; ++i) {
        for (int k = 0; k < 6; ++k) {
            ll id = (k & 1) ? g[i].second.id : g[i].first.id;
            cout << id << " ";
        }
        cout<<endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while (T--) solve();
    return 0;
}

E. Changing the String

可以注意到 a c 和 a b 操作是完全无用的

只统计 BA BC CA CB 操作即可

使字符串最小,所以遍历贪心处理即可

如果当前这位为 a,可直接跳过

如果为 b,考虑变为 a,有两条路线可走:b->a, b->c->a,能走通则变换,否则向下一位

如果为 c,优先向 a 变,c->a, c->b->a, 如果第二条走不到也保留,因为 b 比 c 更优

这里使用 set 储存各操作的位置,同时使用二分查找相对位置之后是否能完成第二种的操作

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;

void solve() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    set<int> BA, BC, CA, CB;
    for (int i = 1; i <= q; ++i) {
        char x, y;
        cin >> x >> y;
        if (x == 'b' && y == 'a') BA.insert(i);
        else if (x == 'b' && y == 'c') BC.insert(i);
        else if (x == 'c' && y == 'a') CA.insert(i);
        else if (x == 'c' && y == 'b') CB.insert(i);
    }
    for (int i = 0; i < n; ++i) {
        char c = s[i];
        if (c == 'a') continue;           

        if (c == 'b') {
            int tmp = 1e9;
            vector<pair<set<int>*, int>> used;

            if (!BA.empty()) {
                int p = *BA.begin();
                tmp = p;
                used = { { &BA, p } };
            }

            else if (!BC.empty()) {
                int p1 = *BC.begin();
                auto it2 = CA.lower_bound(p1);
                if (it2 != CA.end()) {
                    int p2 = *it2;
                    if (p2 < tmp) {
                        tmp = p2;
                        used = { { &BC, p1 }, { &CA, p2 } };
                    }
                }
            }

            if (used.empty()) continue;  

            for (auto [st, pos] : used) st->erase(pos);
            s[i] = 'a';
        }
        else {                            
            int tmp = 1e9;
            char t = 'c';
            vector<pair<set<int>*, int>> used;

            if (!CA.empty()) {
                int p = *CA.begin();
                tmp = p; t = 'a';
                used = { { &CA, p } };
            }

            else if (!CB.empty()) {
                int p1 = *CB.begin();
                auto it2 = BA.lower_bound(p1);
                if (it2 != BA.end()) {
                    int p2 = *it2;
                    if (p2 < tmp) {
                        tmp = p2; t = 'a';
                        used = { { &CB, p1 }, { &BA, p2 } };
                    }
                }
            }

            if (t != 'a' && !CB.empty()) {
                int p = *CB.begin();
                tmp = p; t = 'b';
                used = { { &CB, p } };
            }

            if (used.empty()) continue; 

            for (auto [st, pos] : used) st->erase(pos);
            s[i] = t;
        }
    }

    cout << s << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; 
    cin >> T;
    while (T--) solve();
    return 0;
}

F. Puzzle

Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 11, 2025 16:27 +0800
发表了95篇文章 · 总计15万2千字
永远相信美好的事情即将发生。
使用 Hugo 构建
主题 StackJimmy 设计