Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填

时间:2023-03-10 03:40:39
Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填

我就做了前两题,第一题第一次vp就把我搞自闭跑路了,第二题第二次又把我搞自闭了

A. As Fast As Possible

细节题

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; int n,k; double L,v1,v2;
bool check(double T)
{
int u=; double p=,b=,t=;
u+=k;
double ct=(L-v1*T)/(v2-v1);//需要公交带多久才能到结束位置
if(ct<)return true;
t+=ct;
if(t>T)return false;
p+=v1*ct;
b+=v2*ct; while(u<n)
{
ct=(b-p)/(v1+v2);//相遇要多久
t+=ct;
if(t>T)return false;
p+=v1*ct;
b=p; u+=k;
ct=(L-p-v1*(T-t))/(v2-v1);
if(ct<)return true;
t+=ct;
if(t>T)return false;
p+=v1*ct;
b+=v2*ct;
}
return true;
}
int main()
{
scanf("%d%lf%lf%lf%d",&n,&L,&v1,&v2,&k);
long double l=,r=L;
while(r-l>1e-)
{
long double mid=(l+r)/2.0;
if(check(mid))r=mid;
else l=mid;
}
printf("%.8Lf\n",l); return ;
}

A. As Fast As Possible

B. Connecting Universities

这个贪心题做着做着就懵逼了。。。

有三个做法,其一是按dfs序排序。第i个和第i+k个直接匹配,稍微画画图就是对的

第二是考虑每一条边,这条边最多被经过左右两端关键点数的min

第三是一个节点如果其最多关键点的孩子子树不超过k,那么所有的边都可以两两配对,找到这个点,答案就是所有关键到这个点的和

懒得复制代码了,都很好写