跳到正文

个人记录

2024CSP-S复赛

zhangyoutao0815321约 6 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 6 分钟

版本

  1. v1当前

T1:决斗

之前做过,所以AC。
你看,每次,如果我们把最多都怪当做基准,为了让怪的数量最小,一只怪尽可能地去对比它弱对怪发起进攻。当一只比基准弱的怪想要攻击时,不管它,之后让基准来处理它们。当一只比基准强的怪与战斗时,让它和基准战斗。在最后,答案就是基准的最开始的个数。

C++
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> x(100005, 0);
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		int r;
		cin >> r;
		ans = max(ans, ++x[r]);
	}
	cout << ans << endl;
	return 0;
}

T2:超速检测

主要就是把 a<0a<0,a=0a=0 和 a>0a>0 分类讨论。最终,我的代码TLE了。因为有一个死循环。

C++
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
struct Car
{
	double d, v, a;
	int pSub;
};
double position(double v0, double v1, double a)
{
	return (v1 * v1 - v0 * v0) / 2 / a;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, l, v;
		cin >> n >> m >> l >> v;
		vector<Car> cars(n);
		vector<double> p(m);
		for (int i = 0; i < n; ++i)
		{
			cin >> cars[i].d >> cars[i].v >> cars[i].a;
			if (cars[i].v <= v && cars[i].a <= 0)
			{
				--i;
				--n;
			}
		}
		for (int i = 0; i < m; ++i)
		{
			cin >> p[i];
		}
		int ans1 = 0;
		for (int i = 0; i < n; ++i)
		{
			double overV = cars[i].d + position(cars[i].v, v, cars[i].a);
			if (cars[i].a < 0)
			{
				cars[i].pSub = upper_bound(p.begin(), p.end(), overV) - p.begin() - 1;
			}
			if (cars[i].a == 0 && cars[i].v > v && p.back() > cars[i].d)
			{
				cars[i].pSub = n - 1;
				++ans1;
				continue;
			}
			if (cars[i].a > 0)
			{
				cars[i].pSub = lower_bound(p.begin(), p.end(), overV) - p.begin();
			}
			if (cars[i].pSub < n && cars[i].pSub >= 0 && p[cars[i].pSub] >= cars[i].d && !((overV > l && cars[i].a > 0) || (overV < cars[i].d && cars[i].a < 0)))
			{
				++ans1;
			}
		}
		cout << ans1 << " ";
		int ans2 = 0;
		sort(cars.begin(), cars.end(), [](Car a, Car b){return a.d < b.d;});
		for (int i = 0; i < n;)
		{
			int j = i + 1;
			int minn = cars[i].pSub;
			for (; j < n && cars[j].pSub >= 0 && cars[j].pSub < n && cars[j].d <= p[minn]; ++j) minn = min(minn, cars[j].pSub);
			++ans2;
			i = j;
		}
		if (ans1 == 0)
		{
			cout << m << endl;
		}
		else
		{
			cout << m - ans2 << endl;
		}
	}
	return 0;
}

T3:染色

DFS暴力。

C++
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> a(200005);
vector<int> r;
vector<int> b;
int n;
int t;
int ans;
void dfs(int x)
{
	if (x == n)
	{
		int sum = 0;
		for (int i = 1; i < r.size(); ++i)
		{
			if (r[i] == r[i - 1])
			{
				sum += r[i];
			}
		}
		for (int i = 1; i < b.size(); ++i)
		{
			if (b[i] == b[i - 1])
			{
				sum += b[i];
			}
		}
		ans = max(sum, ans);
		return;
	}
	r.push_back(a[x]);
	dfs(x + 1);
	r.pop_back();
	b.push_back(a[x]);
	dfs(x + 1);
	b.pop_back();
}
int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n;
		ans = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
		}
		dfs(0);
		cout << ans << endl;
	}
	return 0;
}

T4:擂台游戏

(没有递交)

原文