补题--1 Codeforces Round #636 (Div. 3)

本文深入解析了Codeforces Round #636 Div.3 A-D题目的解题思路与技巧,涵盖2的幂次运算、自动迭代器使用、代码优化等关键知识点,适合算法竞赛选手及编程爱好者学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces Round #636 Div. 3

A

题目链接:
https://codeforces.ml/contest/1343/problem/A
这一题我学到了一个除了pow的新知识,在比赛中我用pow怎么都运行不出来,都显示pow不可以运用,结果这个题目中(1<<pw)就指的是2的次方!!!
奇奇怪怪的知识点又学到了,还有就是群里的。

1.for (int& i : p)
cin >> i;

意思是1–p输入i;
2.(1<<k)
意思是2的次方

#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int pw = 2; pw < 30; ++pw) {
			int val = (1 << pw) - 1;
			if (n % val == 0) {
				cerr << val << endl;
				cout << n / val << endl;
				break;
			}
		}
	}
	
	return 0;
}

B

第二题很简单就直接跳过了,哈哈哈,答案没有奇奇怪怪的东西。

C

https://codeforces.ml/contest/1343/problem/C

1.for (auto &it : a)
这个叫做自动迭代器
表示遍历lst这个集合,每次的迭代的其中一个元素是it(auto表示自动推测类型)我在这里又找到更详细的解释

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	//这个地方我没看懂,求大佬讲解啊!!!
	auto sgn = [&](int x) {
		if (x > 0) return 1;
		else return -1;
	};
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (auto &it : a) cin >> it;
		long long sum = 0;
		for (int i = 0; i < n; ++i) {
			int cur = a[i];
			int j = i;
			while (j < n && sgn(a[i]) == sgn(a[j])) {
				cur = max(cur, a[j]);
				++j;
			}
			sum += cur;
			i = j - 1;
		}
		cout << sum << endl;
	}
	
	return 0;
}

D

https://codeforces.ml/contest/1343/problem/D

#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		for (auto &it : a) cin >> it;
		vector<int> cnt(2 * k + 1);
		for (int i = 0; i < n / 2; ++i) {
			++cnt[a[i] + a[n - i - 1]];
		}
		vector<int> pref(2 * k + 2);
		for (int i = 0; i < n / 2; ++i) {
		int l1 = 1 + a[i], r1 = k + a[i];
		int l2 = 1 + a[n - i - 1], r2 = k + a[n - i - 1];
		assert(max(l1, l2) <= min(r1, r2));
		++pref[min(l1, l2)];
		--pref[max(r1, r2) + 1];
		}
		for (int i = 1; i <= 2 * k + 1; ++i) {
		pref[i] += pref[i - 1];
		}
		int ans = 1e9;
		for (int sum = 2; sum <= 2 * k; ++sum) {
		ans = min(ans, (pref[sum] - cnt[sum]) + (n / 2 - pref[sum]) * 2);
		}
		cout << ans << endl;
	}
	
	return 0;
}

感觉越到后面越是膜拜大佬们的代码了,后面两道题目还是等到后来水平再高点再搞吧,实在是有的搞不懂啊。下个星期进行!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值