WA求调 30pts WA(1,2,6,7,9), T(8,10)
查看原帖
WA求调 30pts WA(1,2,6,7,9), T(8,10)
855636
CreamStarlight楼主2024/11/9 00:24

rt + 附带

这道题贪心按我这样的变量怎么打?(violation 可以替换成其他什么的,不过看了题解我居然看不懂贪心怎么打,我是 [!#?@] )

我的代码:

#include<bits/stdc++.h>
#define WYSI 727
using namespace std;
int tasks;
int cars,stests,length,slimit;
bool BOOM[100000+WYSI]={false};
int boomed=0,turnoff=0;
int posit[100000+WYSI];
int inpoint[100000+WYSI],velo[100000+WYSI],accel[100000+WYSI];
int stst=9999999,sted=0;
int accelOn=9999999;

typedef pair<int,int> pii;
stack<pii> violation;

struct limitBall{
	int mstart,mend;
} lb[100000+WYSI];

double round(double x,double precis){
	long long k=x/precis;
	double l=x-k*precis;
	if(l>=precis/2)return (k+1)*precis;
	return k*precis;
}

int nextStop(int poss){
	if(poss<=posit[0])return 0;
	int l=0,r=stests-1;
	int m=(l+r)>>1;
	int res;
	while(l+1!=r){
		if(poss<posit[m]){
			if(posit[m-1]<=poss){
				res=m;
				if(poss==posit[m-1])res--;
				break;
			}
			r=m;
			m=(l+r)>>1;
		}else if(posit[m]<poss){
			if(poss<=posit[m+1]){
				res=m+1;
				break;
			}
			l=m;
			m=(l+r)>>1;
		}else{
			res=m;
			break;
		}
	}
	return res;
}
int prevStop(int poss){
	if(poss>posit[stests-1])return stests-1;
	int l=0,r=stests-1;
	int m=(l+r)>>1;
	int res=999999;
	while(l+1!=r){
		if(poss<posit[m]){
			if(posit[m-1]<=poss){
				res=m-1;
				break;
			}
			r=m;
			m=(l+r)>>1;
		}else if(posit[m]<poss){
			if(poss<=posit[m+1]){
				res=m;
				if(poss==posit[m+1])res++;
				break;
			}
			l=m;
			m=(l+r)>>1;
		}else{
			res=m;
			break;
		}
	}
	if(res==999999)res=l;
	return res;
}

int main(){
	cin>>tasks;
	for(int tt=0;tt<tasks;tt++){
		cin>>cars>>stests>>length>>slimit;
		for(int i=0;i<stests;i++)BOOM[i]=false;
		boomed=0,turnoff=0;
		stst=9999999,sted=0;
		for(int i=0;i<cars;i++){
			int a,b,c;
			cin>>a>>b>>c;
			inpoint[i]=a,velo[i]=b,accel[i]=c;
		}
		for(int i=0;i<stests;i++){
			cin>>posit[i];
			if(posit[i]>sted)sted=posit[i];
			if(posit[i]<stst)stst=posit[i];
		}
		sort(posit,posit+stests);
		for(int i=0;i<cars;i++){
			if(accel[i]>0){
				double violatet=(double)(slimit-velo[i])/accel[i];
				double violated;
				if(violatet<=0) violated=inpoint[i];
				else violated=velo[i]*violatet+0.5*accel[i]*violatet*violatet+inpoint[i];
				if(violated<sted)boomed++;
				if(violated<stst){
					violation.push({0,stests-1});
				}else{
					int st=nextStop((int)round(violated,0.005));
					violation.push({st,stests-1});
				}
			}else if(accel[i]<0){
				int naccel=-accel[i];
				double safet=(double)(velo[i]-slimit)/naccel;
				if(safet<=0) continue;
				else{
					double safed=velo[i]*safet-0.5*naccel*safet*safet+inpoint[i];
					int vioed=prevStop((int)round(safed,0.005));
					int viost=nextStop(inpoint[i]);
					if(viost>vioed){
						continue;
					}else{
						boomed++;
						violation.push({viost,vioed});
					}
				}
			}else{
				if(velo[i]>slimit){
					if(inpoint[i]<=sted){
						boomed++;
						if(inpoint[i]<=stst){
							violation.push({0,stests-1});
						}else{
							int st=nextStop(inpoint[i]);
							violation.push({st,stests-1});
						}
					}
				}
			}
		}
		//p
		if(boomed==0){
			cout<<"0 "<<stests<<endl;
		}else{
			turnoff=1;
			int ptrr=0;
			lb[0]={0,stests-1};
			while(!violation.empty()){
				int ff=violation.top().first,tt=violation.top().second;
				int fff=max(lb[ptrr].mstart,ff),ttt=min(lb[ptrr].mend,tt);
				if(fff>ttt){
					bool anew=true;
					for(int i=0;i<turnoff;i++){
						if(i==ptrr)continue;
						int fff=max(lb[i].mstart,ff),ttt=min(lb[i].mend,tt);
						if(fff>ttt) continue;
						else{
							anew=false;
							ptrr=i;
							lb[ptrr]={fff,ttt};
							break;
						}
					}
					if(anew){
						ptrr=turnoff;
						lb[ptrr]={ff,tt};
						turnoff++;
					}
				}else{
					lb[ptrr]={fff,ttt};
				}
				violation.pop();
			}
			turnoff=stests-turnoff;
			cout<<boomed<<" "<<turnoff<<endl;
		}
	}
	return 0;
}
2024/11/9 00:24
加载中...