Codeforces Round 913 (Div. 3)

在这里插入图片描述

Codeforces Round 913 (Div. 3)

Codeforces Round 913 (Div. 3)

A. Rook

思路:记录当前位置的字母和数字,然后遍历a-h以及1-8组合输出未记录的位置即可。

AC code:

void solve(){
    char a, b; cin >> a >> b;
    map<char, int> mp;
    mp[a] ++;
    mp[b] ++;
    for(char i = 'a'; i <= 'h'; i ++){
        if(!mp[i]) cout << i << b << endl;
    }
    for(char i = '1'; i <= '8'; i ++){
        if(!mp[i]) cout << a << i << endl;
    }
}

B. YetnotherrokenKeoard

思路:模拟,从后往前进行遍历,当遇到删除字符b和B时,记录下来,当遇到其他字符时根据记录情况进行删除。

AC code:

void solve(){
    string s;
    cin >> s;
    string ans = "";
    int B = 0, b = 0;
    for(int i = s.size() - 1; i >= 0; i --){
    	if(s[i] == 'B') B ++;
    	else if(s[i] == 'b') b ++;
    	else if(s[i] >= 'a' && s[i] <= 'z'){
    		if(b){
    			b --;
    			continue;
			}else ans += s[i];
		}else{
			if(B){
				B --;
				continue;
			}else ans += s[i];
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

C. Removal of Unattractive Pairs

题意:给出一个字符串,相邻字符不同可以删除,删除后剩下的字符按原顺序拼接,操作可以进行无数次,字符串最少剩余多少。

思路:记录数量最多的字符数量,若大于全部字符的一半,则最少剩余(mx - (n - mx))个字符,即最多字符的数量减去其他字符数量;

若小于全部字符一半,则奇数剩一个,偶数可以全删。

AC code:

void solve(){
    map<char, int> mp;
    cin >> n >> s;
    int mx = 0;
    for(char x : s) {
        mp[x] ++;
        mx = max(mx, mp[x]);
    }
    if(mx <= n / 2)
        cout << (n % 2 != 0) << endl;
    else
        cout << mx - (n - mx) << endl;
}

D. Jumping Through Segments

题意:游戏从0开始移动,有n段区间,每次移动最多不超过k的单位距离,需要移动n次,第i次移动必须在第i个区间内,最终需要到达第n个区间为游戏胜利,游戏胜利k值最小是多少。

思路:二分,每次记录当前最近/最远可移动到的距离,即最大的左边界和最小的右边界。

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 3e5+10, M = 2001;
const int INF = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int T, n;
PII q[N];

bool check(int k){
    int mn = 0, mx = 0;
    for(int i = 1; i <= n; i ++){
        mn = max(q[i].first, mn - k);
        mx = min(q[i].second, mx + k);
        if(mn > mx) return false;
    }
    return true;
}

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> q[i].first >> q[i].second;
    int l = 0, r = 3e9;
    while(l < r){
        int mid = l + r >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
}

signed main(){
    fast();
    
    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

E. Good Triples

题意:将给出的n分解成三个数相加,且三数每位相加的和等于n每一位相加的和。

思路:每一位相加不能有进位,每一次进位至少会损失单位贡献十而只增加一,所以枚举三个数每一位可能的组合情况即可。

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 3e5+10, M = 2001;
const int INF = 0x3f3f3f3f3f, mod = 998244353;
int T, n, k;
map<int, int> mp;

void init(){
    for(int i = 0; i <= 9; i ++){
        for(int j = 0; j <= 9; j ++){
            for(int u = 0; u <= 9; u ++)
                mp[i + j + u] ++;
        }
    }
}

void solve(){
    cin >> n;
    int cnt = 1, u = n;
    while(u){
        cnt *= mp[u % 10];
        u /= 10;
    }
    cout << cnt << endl;
}

signed main(){
    fast();
    
    init();
    T = 1;
    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[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%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[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 ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值