社区讨论

60求条

P11232[CSP-S 2024] 超速检测参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhj31td8
此快照首次捕获于
2025/11/03 19:54
4 个月前
此快照最后确认于
2025/11/03 19:54
4 个月前
查看原帖
C
#include<bits/stdc++.h>
#define int long long
const double PI=acos(-1.0);
using namespace std;
int read(){
	int sum=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		sum=sum*10+ch-48;
		ch=getchar();
	}
	return sum*f;
}
void print(int x){
	if (x<0){
		putchar('-');
		x=-x;
	}
	if (x>9){
		print(x/10);
	}
	putchar(x%10+48);
	return;
}
double eps=1e-9;
struct car{
	double d,v,a;
}c[100010];
struct node{
	double l,r;
}o[100010];
int pos[100010];
bool cmp(node s1,node s2){
	return s1.r<s2.r;
} 
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--){
		int n,m,L,V;
		cin >> n >> m >> L >> V;
		for (int i=0;i<n;i++){
			cin >> c[i].d >> c[i].v >> c[i].a;
		}
		for (int i=0;i<m;i++){
			cin >> pos[i];
		}
		int cnt=0,num=0;
		for (int i=0;i<n;i++){
			double d=c[i].d,v=c[i].v,a=c[i].a;
			double l=-1,r=-1;
			if (a==0){
				if (v>V){
					l=d,r=L;
				}
			}
			else if (a>0){
				if (v>=V){
					l=d,r=L;
				}
				else{
					double s=(V*V-v*v)/(2*a);
					if (s>=0){
						l=d+s,r=L;
					}
				}
			}
			else{
				if (v>V){
					double op=-v*v/(2*a);
					double lv=min((double)L,d+op);
					double sv=(V*V-v*v)/(2*a);
					l=d,r=d+sv;
					if (r>lv){
						r=lv;
					}
				}
			}
			if (l>=0 && r>l+eps){
				int idx=lower_bound(pos,pos+m,l-eps)-pos;
				if (idx<m && pos[idx]<=r+eps){
					cnt++;
					o[num++]={l,r};
				}
			}
		}
		sort(o,o+num,cmp);
		int mk=0,la=-1;
		for (int i=0;i<num;i++){
			if (la!=-1 && pos[la]>=o[i].l-eps && pos[la]<=o[i].r+eps){
				continue;
			} 
			int rm=upper_bound(pos,pos+m,o[i].r+eps)-pos-1;
			if (rm>=0 && rm<m && pos[rm]>=o[i].l-eps){
				la=rm;
				mk++;
			}
		}
		cout << cnt << " " << m-mk << '\n';
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...