QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#616008 | #8022. Walker | gates_orz | TL | 0ms | 3932kb | C++20 | 2.1kb | 2024-10-05 21:25:42 | 2024-10-05 21:25:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
//#define double long double
#define int LL
double n, m;
const int N = 3e5 + 10;
const int M = N * 2;
const double eps=1e-9;
double p1,v1,p2,v2;
bool check(double x) {
double t1=p1/v1;
double t2=(n-p2)/v2;
t1=x-t1;
t2=x-t2;
if(t1>=eps&&t2>=eps) {
if(v1*t1+v2*t2>=(p2-p1)*2.0)return true;
}
t1=p1*2.0/v1;
t2=(n-p2)*2.0/v2;
t1=x-t1;
t2=x-t2;
if(t1>=eps&&t2>=eps) {
if(v1*t1+v2*t2>=p2-p1)return true;
}
double tmp,tot;
if(v1*x>=p1*2.0) {
tmp=v1*x-p1;
if(tmp>=n)return true;
tot=n-p2;
if(tmp<=p2) {
tot+=(p2-tmp)*2.0;
}
if(v2*x>=tot)return true;
}
/*if(v2*x>=(n-p2)*2.0) {
tmp=v2*x-(n-p2);
if(tmp>=n)return true;
tot=p1;
if(tmp>=p1) {
tot+=(tmp-p1)*2.0;
}
if(v1*x>=tot)return true;
}*/
return false;
}
void solve() {
cin>>n>>p1>>v1>>p2>>v2;
if(p1>=p2) {
swap(p1,p2);
swap(v1,v2);
}
double res=0;
double l=0,r=2e7;
//for(int i=1;i<=100;i++)
while(r-l>eps) {
double mid=(l+r)/2;
if(check(mid))r=mid,res=mid;
else l=mid;
}
//cerr<<"res="<<res<<endl;
//p1走全程
if((p1+n)/v1<=res) {
res=(p1+n)/v1;
}
if((n+n-p1)/v1<=res) {
res=(n+n-p1)/v1;
}
//p2走全程
if((n+n-p2)/v2<=res) {
res=(n+n-p2)/v2;
}
if((n+p2)/v2<=res) {
res=(n+p2)/v2;
}
if((p1/v1)*v2-(n-p2)>=(n-p1)) {
if(res>=(p1/v1))res=p1/v1;
}
if(((n-p2)/v2)*v1-p1>=p2) {
if(res>=(n-p2)/v2)res=(n-p2)/v2;
}
if(res>=max(p2/v2,(n-p1)/v1)) {
res=max(p2/v2,(n-p1)/v1);
}
cout<<fixed<<setprecision(10)<<res<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--)solve();
return 0;
}
/*
1
2 1
a/b/c
a/b/d
e
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
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.8370013756
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3928kb
input:
1 10.0 1.0 10.0 9.0 0.1
output:
1.1000000000
result:
ok found '1.1000000', expected '1.1000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 10.0 8.0 10.0 9.0 0.1
output:
1.2000000000
result:
ok found '1.2000000', expected '1.2000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
1 10.0 8.0 0.1 9.0 10
output:
1.1000000000
result:
ok found '1.1000000', expected '1.1000000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 10.0 2.0 0.1 3.0 10
output:
1.3000000000
result:
ok found '1.3000000', expected '1.3000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 10.0 9.0 0.1 8.0 10.0
output:
1.2000000000
result:
ok found '1.2000000', expected '1.2000000', error '0.0000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 10.0 4.0 0.1 6.0 0.1
output:
60.0000000000
result:
ok found '60.0000000', expected '60.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 10.0 4.5 0.1 6.0 0.1
output:
57.5000000003
result:
ok found '57.5000000', expected '57.5000000', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 10.0 1.0 1.0 8.0 1.0
output:
6.5000000005
result:
ok found '6.5000000', expected '6.5000000', error '0.0000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 10.0 3.0 2.0 7.0 1.0
output:
4.6000000004
result:
ok found '4.6000000', expected '4.6000000', error '0.0000000'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
1 10.0 6.0 2.0 7.0 1.0
output:
3.6666666670
result:
ok found '3.6666667', expected '3.6666667', error '0.0000000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
1 10.0 1.0 1.0 9.0 1.0
output:
6.0000000002
result:
ok found '6.0000000', expected '6.0000000', error '0.0000000'
Test #13:
score: -100
Time Limit Exceeded
input:
1 10000.0 1.0 0.001 1.0 0.001