Codeforces Round 970 (Div. 3)

A

根据题意,a为奇数时不可能成立,a为0且b为奇数时也不可能成立,其余情况都成立

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve() {
    int a, b;
    cin >> a >> b;
    bool f = true;
    if (a % 2 == 1 || a==0&&b%2==1) f = false;
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}

B

因为原始矩阵为美丽矩阵,所以n为平方数,再检查矩阵首尾两行所有字符是否均为‘1’,其余行首尾为’1’,中间为’0’

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve() {
    int n;
    string s;
    cin >> n >> s;

    bool ok = true;
    int a = floor(sqrt(n));
    if (a * a != n) { puts("NO"); return; }
    else {
        for (int i = 0; i < n; i += a) {
            if (i == 0 || i == n - a) {
                for (int j = 0; j < a; j++) if (s[i + j] != '1') { puts("NO"); return; }
            }
            else {
                string ss = "1";
                for (int k = 0; k < a - 2; k++) ss += "0";
                ss += "1";
                if (s.substr(i, a) != ss) { puts("NO"); return; }
            }
        }
    }
    puts("YES");
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

C

根据题目一个一个累加,判断结束条件

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve() {
    int l, r;
    cin >> l >> r;
    int ans = 0;
    int sum = l;
    int i = 1;
    while (1) {
        sum += i;
        if (sum > r) break;
        if (sum == r) { i++; break; }
        i++;
    }
    cout << i << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

D

分析样例二发现一个circle内的所有元素a1,a2,a3...amF(a1) = F(a2) = F(a3) = ··· = f(am),所以可以在每个circle内求值,遍历的时候进行记忆化

#include<bits/stdc++.h>

using namespace std;

void solve() {
	int n;
	string s;
	cin >> n;
	int* p = new int[n + 1];
	bool* st = new bool[n + 1] {0};
	for (int i = 1; i <= n; ++i) cin >> p[i];
	cin >> s;

	vector<int>ans(n + 1);
	for (int i = 1; i <= n; ++i) {
		if (!st[i]) {
			st[i] = 1;
			vector<int>circle;
			int c = p[i];
			circle.push_back(c);
			c = p[c];
			st[c] = 1;
			while (c != p[i]) {
				circle.push_back(c);
				c = p[c];
				st[c] = 1;
			}
			int cnt = 0;
			for (int e : circle) {
				if (s[e - 1] == '0')
					cnt++;
			}
			for (int e : circle) ans[e] = cnt;
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
	cout << endl;

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

E

n是偶数时,我们只要分别找到奇数位和偶数位相同字符个数的最大值max1,max2,答案就是n - max1 - max2

n是奇数时,需要考虑删除一个字符后产生的影响,我们可以倒序遍历每一个字符,统计删除aiai前面和ai后面奇数位偶数位的字母数量,求最大值

#include<bits/stdc++.h>

using namespace std;

void solve() {
	int n;
	string s;
	cin >> n >> s;
	s = " " + s;
	int cnt[3][27]{ 0 };
	int max1 = 0, max2 = 0;

	for (int i = 1; i < s.size(); ++i) {
		if (i & 1) {
			cnt[1][s[i] - 'a']++;
			max1 = max(max1, cnt[1][s[i] - 'a']);
		}
		else {
			cnt[2][s[i] - 'a']++;
			max2 = max(max2, cnt[2][s[i] - 'a']);
		}
	}
	if (n % 2 == 0) cout << n - max1 - max2 << endl;
	else {
		int b[3][30] = { 0 };
		int mx = 0;
		for (int i = n; i >= 1; --i) {
			int k1 = 0, k2 = 0;
			if (i & 1) cnt[1][s[i] - 'a']--;
			else cnt[2][s[i] - 'a']--;
			for (int j = 0; j < 26; j++) {
				int x = cnt[1][j], y = cnt[2][j];
				x += b[2][j];
				y += b[1][j];
				k1 = max(k1, x);
				k2 = max(k2, y);
			}
			mx = max(mx, k1 + k2);
			if (i % 2 == 1) b[1][s[i] - 'a']++;
			else b[2][s[i] - 'a']++;
		}
		cout << n - mx << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

F

逆元,以后再补

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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值