Codeforces B. Universal Solution (构造字符串 / 思维) (Round 91 Rated for Div.2)

传送门

题意: 给出机器人的一段出拳序列s(只有 'R’拳头,'S’剪刀,'P’布组成)。让你构造一串出拳序列c和机器人比赛。
在这里插入图片描述
比赛得分机制为下:

  • 机器人选择pos = 1开始与你的1开始往后一 一对应比较,若你在某个位置赢了该回合的得分+1,若输了或平局没有得分,该回合得分为win(1)。
  • 机器人选择pos = 2开始与你的1开始往后一一对应比较,该回合得分win(2).
  • ……
  • 构造的串要使得(win(1) + win(2) + …… + win(n) / n最大。

在这里插入图片描述
思路:

  • 仔细分析下来就是(c[1]对战整个s的得分 + c[2]对战s的得分 + …… +c[n]对战整个s的得分) / n.
  • 而要使结果max,就需要用s中雷同最多的字符的反字符来构造成n个长度的串c。

代码实现:

#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int  inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll   mod = 1e9 + 7;
const int  N = 2e5 + 5;

int t;
map<char, int> cnt;
map<char, char> mp{{'R', 'P'}, {'S', 'R'}, {'P', 'S'}};

signed main()
{
    IOS;

    cin >> t;
    while(t --){
        string s; cin >> s;
        int mx = 0;
        cnt.clear();
        for(int i = 0; i < s.size(); i ++)
            mx = max(mx, ++cnt[s[i]]);
        for(char x : {'R', 'S', 'P'}){
            if(cnt[x] == mx){//找到雷同最多的字母
                cout << string(s.size(), mp[x]) << endl; //输出其反字母形成的串
                break;
            }
        }
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Educational Codeforces Round 146 (Rated for Div. 2)比赛中,有关于一个节点数量为n的问题。根据引用的结论,无论节点数量是多少,都可以将其分成若干个大小为2或3的区间使其错排,从而减少花费。根据引用的推导,我们可以通过组合数和差量来表示剩余的花费。而引用进一步推广了这个结论,可以使得任意长度的一段错排花费代价为边权和的两倍,并且通过贪心算法使得更多的边不被使用。以此来解决与节点数量相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Educational Codeforces Round 146 (Rated for Div. 2)(B,E详解)](https://blog.csdn.net/TT6899911/article/details/130044099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Educational Codeforces Round 83 (Rated for Div. 2) D](https://download.csdn.net/download/weixin_38562130/14878888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值