Educational Codeforces Round 73 (Rated for Div. 2)

比赛链接:Educational Codeforces Round 73 (Rated for Div. 2)

官方题解:Educational Codeforces Round 73 Editorial

A. 2048 Game

题意

如果一个只包含 \(2\) 的幂次的集合,问能否从中选择一些数使得和为 \(2048\)。

思路

不断合并直到凑到 \(2048\)。

代码

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--) {
        map<int, int> mp;
        int n;
        cin >> n;
        int flag = 0;
        for(int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            if(x == 2048) {
                flag = 1;
            }
            mp[x]++;
        }
        int tmp = 2048;
        for(int i = 1; i <= 2048; i *= 2) {
            if(mp[i] >= tmp) {
                flag = 1;
                break;
            } else {
                mp[i * 2] += mp[i] / 2;
            }
            tmp /= 2;
        }
        if(flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

B. Knights

题意

给定 \(n * n\) 的棋盘,放置黑白两种马,问怎么放这些马,使得相互攻击的棋子最多。

思路

隔着放就行。

代码

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if((i + j) % 2) {
                cout << "B";
            } else {
                cout << "W";
            }
        }
        cout << endl;
    }
    return 0;
}

C. Perfect Team

题意

要组队参加 ICPC 比赛,有三种学生:coder,mathematician,普通人。每个队伍至少一名 coder,至少一名 mathematician,并且必须是三个人。现在给定每种学生的人数,求最多能组多少支队伍。

思路

设总人数为 \(x\)。则队伍数最多为 \(\lfloor x / 3 \rfloor\)。然后分别看一下 coder 的人数和 mathematician 的人数是否多于 \(\lfloor x / 3 \rfloor\),取三者最少的就是答案。

代码

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--) {
        int c, m, x;
        cin >> c >> m >> x;
        int sum = c + m + x;
        sum /= 3;
        if(c < sum) {
            sum = c;
        }
        if(m < sum) {
            sum = m;
        }
        cout << sum << endl;
    }
    return 0;
}

D. Make The Fence Great Again

题意

给定 \(n\) 块板,第 \(i\) 块板的高度为 \(a_i\),要使相邻两块板的高度不同,可以增加板的高度,增加的代价为 \(b_i\),求最少的代价。

思路

每块板要么不增加,要么增加 \(1\),要么增加 \(2\)。每次从上一块板的三种状态转移过来即可。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10;
const ll inf = 1e18;

ll a[maxn], b[maxn], dp[maxn][3];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--) {
        int n;
        cin >> n;
        for(int i = 1; i <= n; ++i) {
            cin >> a[i] >> b[i];
            for(int j = 0; j < 3; ++j) {
                dp[i][j] = inf;
            }
        }
        dp[1][0] = 0;
        dp[1][1] = b[1];
        dp[1][2] = b[1] * 2;
        for(int i = 2; i <= n; ++i) {
            for(int j = 0; j <= 2; ++j) {
                for(int k = 0; k <= 2; ++k) {
                    if(a[i - 1] + k != a[i] + j) {
                        dp[i][j] = min(dp[i][j], dp[i - 1][k] + b[i] * j);
                    }
                }
            }
        }
        ll ans = min({dp[n][0], dp[n][1], dp[n][2]});
        cout << ans << endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/wulitaotao/p/11594221.html

时间: 2024-10-10 22:59:19

Educational Codeforces Round 73 (Rated for Div. 2)的相关文章

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again

题目链接:http://codeforces.com/contest/1221/problem/D 题意:给一个序列,要求修改某些位置的数字,使得这个序列的相邻的数不相等,每次修改,只能使得某个数字加一,每次修改的代价为b[i],求最小所需的代价. 解题思路:经过简单分析,我们可以知道,每个数字最多只需要修改两次,那么我们定义dp[i][j]使得前j个数字相邻数字不等的最小代价,且最后一个数字修改了i次.那么答案即为min{dp[0][n],dp[1][n],dp[2][n]}. #includ

Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game

链接: https://codeforces.com/contest/1221/problem/A 题意: You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations wi

Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)

链接: https://codeforces.com/contest/1221/problem/B 题意: You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board. A knight is a chess pi

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)

链接: https://codeforces.com/contest/1221/problem/D 题意: You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

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

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w