当前位置:网站首页>20 years' Shanghai station D question Walker (two points, concise)
20 years' Shanghai station D question Walker (two points, concise)
2022-06-23 12:52:00 【Int i】
Title Description
As a world-famous traveler, Prof. Pang's research interest is to travel as many places as possible in his life.
We have a segment [0,n]{[0, n]}[0,n]. There are two travelers on it. The first one is on position p1p_1p1 with velocity v1v_1v1 (which means s/he can walk v1v_1v1 unit on the segment per second). The second one is on position p2p_2p2 with velocity v2v_2v2.
From their respective beginning points, travelers can walk on the segment. They cannot walk outside the segment. Whenever they want to change their direction, they can turn around immediately.
Please help Prof. Pang to calculate the minimum possible time by which every position of the segment is passed by at least one traveler.
Input description :
The first line contains one integer test (1≤test≤10000)test~(1\le test\le 10000)test (1≤test≤10000) -- the number of test cases.
The i-th of the next test lines contains five numbers n,p1,i,v1,i,p2,i,v2,in, p_{1, i}, v_{1, i}, p_{2, i}, v_{2, i}n,p1,i,v1,i,p2,i,v2,i (0<n≤100000 < n \le 100000<n≤10000, 0≤p1,i,p2,i≤n0\le p_{1, i},p_{2, i} \le n0≤p1,i,p2,i≤n, 0.001≤v1,i,v2,i≤10000.001 \le v_{1, i},v_{2, i} \le 10000.001≤v1,i,v2,i≤1000). All numbers have at most 3 digits after the decimal point.Output description :
For each test case, we should output one number -- the minimum time that every position of the segment is passed by at least one traveler.
Your answer is considered correct if its absolute or relative error does not exceed 10−610^{-6}10−6.
Input
2 10000.0 1.0 0.001 9999.0 0.001 4306.063 4079.874 0.607 1033.423 0.847
Output
5001000.0000000000 3827.8370013755
The question :0-n On one-dimensional coordinates of , Give the position and velocity of any two points , They can go in any direction at any time , Ask these two points to complete all the places together in the least time .
Ideas :
First, judge whether the previous position is smaller , No. swap Turn it over , The front one is a, The back is b
It's not particularly difficult to do questions , There are four situations :
1. Only a perhaps b, The answer is :(x+min(a.x,x-a.x))/a.v, and (x+min(b.x,x-b.x))/b.v), because a perhaps b You can choose whether to reach the left endpoint first or the right endpoint
2.a and b Cross walk , And cross and go straight . The answer is :max(b.x/b.v,(x-a.x)/a.v), The maximum usage time is the answer .

3. Left by a Come and go , Right by b Come and go . The middle point is mid, be mid It must be a and b Between starting points , Because once a Right past b The starting point , that b You don't have to go to the right ,b It's useless. , It belongs to the first case .

This is mid On the left is a Come and go , On the right is b Come and go
a The shortest path is :mid+min(a.x,mid-a.x)
b The shortest path is :l-mid+min(n-b.x,b.x-mid)
And the answer to decimals , The maximum on both sides is the answer , It must be the best when the left and right use time are the same , This process can be divided into two .
There is another important point about this question , It's about precision , So that some of the questions have 100 Second half for
But like my code below , No, long double, No, 1e-10, No multi decimal output
The precision card of this question is the result returned by the dichotomy :return max(l/a.v+(min(a.x,l-a.x))/a.v,((x-l)+min(x-b.x,b.x-l))/b.v);
It must be max() Of , You cannot return only one , This depends on the code specification .
Code :
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define dou double
#define EXP 0.0000001
#define M 1000005
int T;
dou x;
struct Node{
dou x,v;
}a,b;
bool check(dou mid){
return (mid+min(a.x,mid-a.x))/a.v>((x-mid)+min(x-b.x,b.x-mid))/b.v;
}
dou solve(){
dou l=a.x,r=b.x;
while(r-l>EXP){
dou mid=(l+r)/2;
if(check(mid)) r=mid;
else l=mid;
}
return max(l/a.v+(min(a.x,l-a.x))/a.v,((x-l)+min(x-b.x,b.x-l))/b.v); // This must be max, Returning only the left time or the right time will WA
}
int main(){
cin>>T;
while(T--){
cin>>x>>a.x>>a.v>>b.x>>b.v;
if(a.x>b.x) swap(a,b);
dou ans=(x+min(a.x,x-a.x))/a.v;
ans=min(ans,(x+min(b.x,x-b.x))/b.v);
ans=min(ans,max(b.x/b.v,(x-a.x)/a.v));
printf("%.6lf\n",min(ans,solve()));
}
return 0;
}
边栏推荐
- 【网站架构】10年数据库设计浓缩的绝技,实打实的设计步骤与规范
- R language is used to build ordered multi classification logistic regression model, ordinal or. The display function obtains the summary statistical information of the ordered logistic regression mode
- 项目测试一半,需求要变更,测试人员怎么办?
- [system architecture] - five styles of software architecture
- AssetBundle resource management
- QT5知识:字符串列表QStringListModel
- Stimulsoft Ultimate Reports 2022.3.1
- R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
- kubernetes comfig subpath
- 20年上海站D题Walker(二分,简洁)
猜你喜欢

Huawei cloud gaussdb heavily released HTAP for commercial use, defining a new paradigm of cloud native database 2.0

Oracle数据库的主导地位被云竞争对手逐渐侵蚀

With 32 qubits! Rigetti computing enters the UK quantum computing market

Transformers are RNNs (linear transformer)论文阅读

【UVM入门 ===> Episode_7 】~ sequence、sequence item、sequencer、driver

测试时间不够怎么办?

Ecological Wanli database and Westone completed compatible certification to jointly build a network security ecosystem

MySQL使用ReplicationConnection導致的連接失效分析與解决

技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放

Halcon principle: Auto_ Threshold operator
随机推荐
R语言dplyr包arrange函数排序dataframe数据、通过多个数据列排序dataframe数据(默认是升序排序)
QT knowledge: detailed explanation of view frame qgraphicswidget
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
夏日炎炎玩转新加坡:盘点室内景点和夜游好去处
Voice module: pyttsx sound change project
Playing in Singapore in the hot summer: an inventory of indoor attractions and good places for night trips
R语言使用构建有序多分类逻辑回归模型、ordinal.or.display函数获取有序逻辑回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、汇总统计结果保存到csv
Meta said that the UK security law will "scan all private information", which risks infringing on users' privacy
C#学习(高级课程)Day14——特性
C#学习(高级课程)Day13——反射
Network foundation and framework
Solve "thread 1:" -[*.collectionnormalcellview isselected]: unrecognized selector sent to instance 0x7F "
New project, how to ensure the coverage of the test?
kubernetes comfig subpath
Wallys/DR6018-S/ 802.11AX MU-MIMO OFDMA / 2* GE PORTS/WIFI 6e / BAND DUAL CONCURRENT
C # learning (advanced course) day15 - exception handling and namespace
一个 BUG 开发表示用户不会这样操作,无需修复,测试人员如何应对?
What should I do if a serious bug occurs within the scope of my own test and I am about to go online?
SQL adds the problem of duplicate table records.
手机开户有什么风险吗?开户安全吗?