Codeforces Round 910 (Div. 2)

A

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 200005;
const int MOD = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int ans = 0;
	s = '?' + s;
	int cnta = 0, cntb = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'A')
			cnta++;
		else
			cntb++;
	}
	if (cntb == k) {
		cout << 0 << '\n';
		return;
	}
	cout << 1 << '\n';
	if (cntb > k) {
		for (int i = 1; i<= n; i++) {
			if (s[i] == 'B') {
				cntb--;
			}
			if (cntb == k) {
				cout << i << ' ' << 'A' << '\n';
				return;
			}
		}
	}
	else {
		for (int i = 1; i <= n; i++) {
			if (s[i] == 'A') {
				cntb++;
			}
			if (cntb == k) {
				cout << i << ' ' << 'B' << '\n';
				return;
			}
		}
	}
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

B

从后往前,遇到大的就分

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 200005;
const int MOD = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}	
ll cnt[maxn];
bool check(int x) {
	if ((x & -x) == x)return true;
	else return false;
}
inline void solve() {
	int n; cin >> n;
	ll ans = 0;
	memset(cnt, 1, sizeof(cnt));
	vector<ll>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll t = a[n - 1];
	ll x = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] <= t) {
			t = a[i];
			continue;
		}
		int num = a[i] / t + (a[i] % t != 0);
		ans += num - 1;
		t = a[i] / num;
	}
	cout << ans << '\n';
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

C

设sum=n+m-2,显然k<sum,(sum-k)%2=1都不行,两种构造方法如下

(用的别人的图)

 

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;

int main(){

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n, m, k;
        cin >> n >> m >> k;
        if (k < n + m - 2){
            cout << "NO" << '\n';
            continue;
        }
        if (k % 2 != (n + m - 2) % 2){
            cout << "NO" << '\n';
            continue;
        }
        vector<vector<int> > a1(n, vector<int>(m - 1)), a2(n - 1, vector<int>(m));
        for(int i = 0; i < n - 1; i++){
            if (i % 2 == 0){
                a2[i][0] = 1;
            }
        }
        for(int i = 0; i < m - 1; i++){
            if ((n + i - 1) % 2 == 0){
                a1[n - 1][i] = 1;
            }
        }
        if (k % 4 != (n + m - 2) % 4){
            a1[0][0] = a1[1][0] = 1;
        }
        a2[n - 2][m - 1] = a1[n - 1][m - 2] ^ 1;
        a1[n - 2][m - 2] = a1[n - 1][m - 2];
        a2[n - 2][m - 2] = a2[n - 2][m - 1];
        cout << "YES" << '\n';
        for(int i = 0; i < a1.size(); i++){
            for(auto x : a1[i]){
                cout << (x ? "R" : "B") << ' ';
            }
            cout << '\n';
        }
        for(int i = 0; i < a2.size(); i++){
            for(auto x : a2[i]){
                cout << (x ? "R" : "B") << ' ';
            }
            cout << '\n';
        }
    }

}

D

找最大左边界与最小右边界

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int maxn = 20;
const int MOD = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}	
int d1[maxn][maxn], d2[maxn][maxn];

inline void solve() {
	int n; cin >> n;
	vector<int>a(n);
	vector<int>b(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	ll ans = 0;
	ll maxl = 0, minr = 1e9 + 7;
	for (int i = 0; i < n; i++) {
		ll L = min(a[i], b[i]);
		ll R = max(a[i], b[i]);
		maxl = max(maxl, L);
		minr = min(minr, R);
		ans += R - L;
	}
	cout << max(ans, ans + 2ll * (maxl - minr)) << '\n';

}

signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值