我是靠谱客的博主 激动信封,这篇文章主要介绍The 2020 ICPC Asia Shanghai Regional Contest D. Walker链接题意思路代码,现在分享给大家,希望可以做个参考。

链接

https://ac.nowcoder.com/acm/contest/9925/D

题意

线段上有两点以各自速度随意移动,问最少经过多久两点移动的路径能覆盖整段线段。

思路

二分时间。

考虑如下情况:

  • 某点能覆盖整段线段
  • 左边的点向右移动,右边的点向左移动
  • 左边的点向左移动,右边的点向右移动(两点可先向中间移动再折返)
    • 都不先向中间移动
    • 左边的点先向中间移动再折返,右边的点向右移动
    • 右边的点先向中间移动再折返,左边的点向右移动
    • 两点都先向中间移动再折返

代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h> #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second using namespace std; typedef double DB; typedef long long LL; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<PII> VPII; //head DB n,p1,p2,v1,v2; bool check(DB t) { DB a,b; a=min(p2-p1,max(0.0,v1*t-2*p1)); b=min(p2-p1,max(0.0,v2*t-2*(n-p2))); if(v1*t>=p1&&v2*t>=n-p2&&a+b>=p2-p1) return true; if(v1*t>=p1&&v2*t>=n-p2+2*(p2-p1-a)) return true; if(v1*t>=p1+2*(p2-p1-b)&&v2*t>=n-p2) return true; a=min(p2-p1,max(0.0,(t-p1/v1)*v1/2)); b=min(p2-p1,max(0.0,(t-(n-p2)/v2)*v2/2)); if(t*v1>=p1&&t*v2>=n-p2&&a+b>=p2-p1) return true; return false; } int main() { //freopen("E:/OneDrive/IO/in.txt","r",stdin); int tt; scanf("%d",&tt); while(tt--) { scanf("%lf%lf%lf%lf%lf",&n,&p1,&v1,&p2,&v2); if(p1>p2) swap(p1,p2),swap(v1,v2); DB l=0,r=min({min(n+p1,n+n-p1)/v1,min(n+p2,n+n-p2)/v2,max((n-p1)/v1,p2/v2)}); for(int i=0;i<200;i++) { DB mid=(l+r)/2.0; if(check(mid)) r=mid; else l=mid; } printf("%.10fn",r); } return 0; }

最后

以上就是激动信封最近收集整理的关于The 2020 ICPC Asia Shanghai Regional Contest D. Walker链接题意思路代码的全部内容,更多相关The内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部