题解归档 - cf104077F

题解归档 - cf104077F

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

F - Hotel

Teams are independent. A double room can contain at most two contestants; if it contains two,
they must be from the same team and have the same gender. A double room may also be used by just
one contestant.

For one team:

  • putting everyone alone costs 3*min(c1,c2);
  • if any two letters are equal, one valid pair in a double room plus one solo room costs
    c2 + min(c1,c2).

Take the cheaper valid option for every team and sum.

代码

来源:problems/cf104077F/solution.cpp

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    ll c1, c2;
    cin >> n >> c1 >> c2;
    ll ans = 0;
    ll solo = min(c1, c2);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        bool pairable = s[0] == s[1] || s[0] == s[2] || s[1] == s[2];
        ll cur = 3 * solo;
        if (pairable) cur = min(cur, c2 + solo);
        ans += cur;
    }
    cout << ans << '\n';
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf104077F
文章链接:https://www.fangshaonian.cn/archives/153/
最后编辑:2026 年 6 月 28 日 19:02 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 7 + 7 =
快来做第一个评论的人吧~