Codeforces Round 924 - A、B、C

文章目录

  • [A. Rectangle Cutting](#A. Rectangle Cutting)
  • [B. Equalize](#B. Equalize)
  • [C. Physical Education Lesson](#C. Physical Education Lesson)

A. Rectangle Cutting

观察拼接规律,只能从中间切割,考虑边长单双数和切割后是否等于另一条边

C++ 复制代码
#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n,m;
	cin >> n >> m;
	int flag = 0;
	if(n % 2 == 0 && n / 2 != m) flag = 1;
	else if(m % 2 == 0 && m / 2 != n) flag = 1;
	
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

B. Equalize

在一个长度为元素个数的区间里即可,可以双指针思路简化时间复杂度(前几次提交未用双指针,直接使用std::distance都tle了)

C++ 复制代码
#include<bits/stdc++.h>

using namespace std;

void solve()
{
	set<int> st;
	int n;
	cin >> n;
	int sum = n;
	while(n--)
	{
		int m;
		cin >> m;
		st.insert(m);
	}
	vector<int> vct;
	for(auto &x : st) vct.push_back(x);
	int ans = 1;
	auto x = vct[0];
	for(int i = 1; i < vct.size() && vct[i] <= vct[0] + sum - 1; i ++ ) ans ++;
	int i = 0, j = ans - 1;
	for(i = 1; i < vct.size(); i ++ )
	{
		for(;vct[j] <= vct[i] + sum -1 && j < vct.size(); j ++ ) ;
		j = j - 1;
		ans = max(ans, j - i + 1);
	}
	cout << ans << endl;
}

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

C. Physical Education Lesson

上坡位置:n-x是2k-2的倍数;下坡位置:n+x-2是2k-2的倍数。遍历所有k,再看k是否满足该位是x

C++ 复制代码
#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n, x;
	cin >> n >> x;
	set<int> s;
	// 在上坡
	{
		auto check = [&](int y){
			if (y % 2 == 1) return;
			int k = (y + 2) / 2;
			if (k != 1) s.insert(k);
		};
		
		int r = n - x;
		for(int i = 1; i * i <= r; i++){
			check(i);
			if (i * i != r) check(r / i);
		}
	}
	// 在下坡
	{
		auto check = [&](int y){
			if (y % 2 == 1) return;
			int k = (y + 2) / 2;
			if (k != 1) s.insert(k);
		};
		
		int r = n + x - 2;
		for(int i = 1; i * i <= r; i++){
			check(i);
			if (i * i != r) check(r / i);
		}
	}
	int ans = 0;
	for(auto y : s){
		int r = n % (2 * y - 2);
		if (r == 0) r += 2 * y - 2;
		int t = 0;
		if (r <= y) t = r;
		else t = 2 * y - 2 - r + 2;
		if (t == x) ans += 1;
	}
	cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T;
	cin >> T;
	while(T--) solve();
}
相关推荐
CoovallyAIHub2 小时前
港大&字节重磅发布DanceGRPO:突破视觉生成RLHF瓶颈,多项任务性能提升超180%!
深度学习·算法·计算机视觉
感哥2 小时前
C++ STL 常用算法
c++
CoovallyAIHub3 小时前
英伟达ViPE重磅发布!解决3D感知难题,SLAM+深度学习完美融合(附带数据集下载地址)
深度学习·算法·计算机视觉
saltymilk13 小时前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥13 小时前
C++ lambda 匿名函数
c++
沐怡旸19 小时前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥20 小时前
C++ 内存管理
c++
聚客AI20 小时前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
大怪v1 天前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
惯导马工1 天前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法