比赛 |
2022级DP专题练习赛2 |
评测结果 |
AAAAAAAAA |
题目名称 |
基站建设 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
4.383 s |
代码语言 |
C++ |
内存使用 |
112.75 MiB |
提交时间 |
2023-02-13 21:35:06 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=5000000+5;
struct sdf{
ld x,y,k;
}p[N];
int n;
ld m,f[N],vv[N];
int q[N],id[N],tmp[N],tp=0;
vi b;
inline ld slope(int i,int j){
return (f[j]-p[j].y-f[i]+p[i].y)/(p[j].x-p[i].x);
}
void cdq(int l,int r){
if (l==r)return ;
int mid=(l+r)/2;
cdq(l,mid);tp=0;
for (int i=l;i<=mid;i++){
while(tp>1&&slope(q[tp-1],q[tp])>=slope(q[tp],id[i]))q[tp--]=0;
q[++tp]=id[i];
}
for (int i=mid+1,st=tp;i<=r;i++){
while(st>1&&slope(q[st-1],q[st])>p[i].k)st--;
int j=q[st];
f[i]=min(f[i],-p[i].k*p[j].x-p[j].y+f[j]+vv[i]);
}
cdq(mid+1,r);
for (int k=l,i=l,j=mid+1;k<=r;k++){
if (j>r||(i<=mid&&p[id[i]].x<p[id[j]].x))tmp[k]=id[i++];
else tmp[k]=id[j++];
}
for (int i=l;i<=r;i++)id[i]=tmp[i];
}
inline ld read(){
ll ans=0;char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<1)+(ans<<3)+(ch^48),ch=getchar();
return ans;
}
int main(){
freopen ("2012sdoi_jzjs.in","r",stdin);
freopen ("2012sdoi_jzjs.out","w",stdout);
scanf("%d%lf",&n,&m);
for (int i=1;i<=n;i++){
ld x=read(),r=read(),v=read();
if (abs(m-x)<=r)b.pb(i);
r=sqrt(r);id[i]=i;
p[i].x=1.0/r;p[i].y=x/(2.0*r);p[i].k=-x/2;
f[i]=1e18;vv[i]=v;
}
f[1]=vv[1];
cdq(1,n);
ld ans=1e18;
for (int i=0;i<b.size();i++)ans=min(ans,f[b[i]]);
printf("%.3lf\n",ans);
}