AC

名字不要取太长像我这样应该刚刚好  •  12天前



评论:

`

#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
const int nsize = 1e5;
int d[nsize], v[nsize], a[nsize], p[nsize];
struct area {
	int left, right;
	bool operator < (area a2) {
		return right < a2.right;
	}
};
vector<area> li; //超速摄像头区间
int main() {
	int t, n, m, L, V;
	cin >> t;
	while (t--) {
		cin >> n >> m >> L >> V;
		li.clear();
		for (int i = 1; i <= n; i++) cin >> d[i] >> v[i] >> a[i];
		for (int i = 1; i <= m; i++) cin >> p[i];
		for (int i = 1; i <= n; i++) {
			if (a[i] == 0) { //匀速运动
				if (v[i] > V) { //如果一开始超速,就一直超速
					int start = lower_bound(p + 1, p + m + 1, d[i]) - p;
					if (start <= m) li.push_back({ start,m });
				}
			}
			else if (a[i] > 0) { //匀加速运动
				if (v[i] > V) {   //如果一开始超速,就一直超速
					int start = lower_bound(p + 1, p + m + 1, d[i]) - p;
					if (start <= m) li.push_back({ start,m });
				}
				else { //如果一开始没超速,一定是加速到某个位置,到最后都超速
					double pos = d[i] + (V * V - v[i] * v[i]) / 2.0 / a[i];
					//公式计算出的位置速度正好是V,那个位置是不算超速的
					int start = upper_bound(p + 1, p + m + 1, pos) - p; 
					if (start<=m)  li.push_back({ start,m });
				}
			}
			else { //匀减速运动
				if (v[i] > V) { //一开始超速才可能超速
					double pos = d[i] + (V * V - v[i] * v[i]) / 2.0 / a[i];
					int start = lower_bound(p + 1, p + m + 1, d[i]) - p;
					int end = lower_bound(p + 1, p + m + 1, pos) - p;
					//公式计算出的位置速度正好是V,那个位置是不算超速的,去掉那个摄像头
					if (p[end] >= pos) end--;
					if (start <= end) li.push_back({ start,end });
				}
			}
		}
		int cnt = 0, last = 0;
		sort(li.begin(), li.end());
		for (area b : li) { //区间选点模板
			if (b.left > last) {
				cnt++;
				last = b.right;
			}
		} 
		cout << li.size() << " " <<  m-cnt << endl;
	}
	return 0;
}`

☀️☃️☃️☃️☀️  •  12天前

请先登录,才能进行评论