求调
查看原帖
求调
1032437
oulii楼主2024/11/21 22:23
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=2e9;
int n,Q,mp1,mp2;
double f[2][32][21],ans[100001];//到i加油站速度2^p1*3^p2需要最小时间为f[i][p1][p2]
struct sta
{
	double x,t,p;
}a[100004];
struct ques
{
	double y;
	int id;
}q[100004];
bool cmp(ques x,ques y)
{
	return x.y<y.y;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	ios::sync_with_stdio(0);
	cin>>n>>Q;
	for(int i=1;i<=n;i++)
		cin>>a[i].x>>a[i].t>>a[i].p;
	for(int i=1;i<=Q;i++)
	{
		cin>>q[i].y;
		q[i].id=i;
		ans[i]=inf;
	}
	sort(q+1,q+Q+1,cmp);
	for(int p1=0;p1<=31;p1++)
		for(int p2=0;p2<=20;p2++)
			f[1][p1][p2]=f[0][p1][p2]=inf;
//	memset(ans,127,sizeof(ans));
//	memset(f,127,sizeof(f));
	f[0][0][0]=0;a[n+1].x=2e9;
	for(int i=1,j=1;i<=n;i++)
	{
		int i0=i&1,i1=i0^1;
		for(int p1=0;p1<=min(mp1,31);p1++)
			for(int p2=0;p2<=min(mp2,20);p2++)
			{
				ll v=(1<<p1)*pow(3,p2);
				if(v<=1e9)
				{
					if(a[i].p==2)
						f[i0][p1+1][p2]=f[i1][p1][p2]+a[i].t+(a[i].x-a[i-1].x)/v;
					if(a[i].p==3)
						f[i0][p1][p2+1]=f[i1][p1][p2]+a[i].t+(a[i].x-a[i-1].x)/v;
					if(a[i].p==4)
						f[i0][p1+2][p2]=f[i1][p1][p2]+a[i].t+(a[i].x-a[i-1].x)/v;
				}
				f[i0][p1][p2]=min(f[i0][p1][p2],f[i1][p1][p2]+(a[i].x-a[i-1].x)/v);
			} 
		if(a[i].p==2)mp1++;
		if(a[i].p==3)mp2++;
		if(a[i].p==4)mp1+=2;
		int j1=j;
		for(int p1=0;p1<=min(mp1,31);p1++)
			for(int p2=0;p2<=min(mp2,20);p2++)
			{
				int nw=j;
				while(a[i+1].x>=q[nw].y && nw<=Q)
				{
					ll v=(1<<p1)*pow(3,p2);
					ans[q[nw].id]=min(ans[q[nw].id],f[i0][p1][p2]+(q[nw].y-a[i].x)/v);
					nw++;
				}
				j1=nw;
			}
		//cout<<ans[8]<<" ";
		j=j1;
		if(j>Q)break;
		for(int p1=0;p1<=min(mp1,31);p1++)
			for(int p2=0;p2<=min(mp2,20);p2++)
				f[i1][p1][p2]=inf;
		//cout<<ans[8]<<endl;
	}
	for(int i=1;i<=Q;i++)
		printf("%.7f\n",ans[i]);
	return 0;
}
  • 有几个数一直输出inf
2024/11/21 22:23
加载中...