QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242709#7331. The Catcher in the RyePetroTarnavskyi#AC ✓210ms3872kbC++201.8kb2023-11-07 16:30:132023-11-07 16:30:13

Judging History

你现在查看的是最新测评结果

  • [2023-11-07 16:30:13]
  • 评测
  • 测评结果:AC
  • 用时:210ms
  • 内存:3872kb
  • [2023-11-07 16:30:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

db hipot(db a, db b)
{
	return sqrt(a * a + b * b);
}

db h, a, b, c, va, vb, vc;

db f(db x, db y)
{
	db res = 0;
	res += hipot(a, x) / va;
	res += hipot(b, (y - x)) / vb;
	res += hipot(c, h - y) / vc;
	
	return res;
}

db fBC(db x)
{
	double l = 0, r = h;
	
	const db coef = (-1 + sqrt(5)) / 2;
	const int M = 47;
	db m1 = r - coef * (r - l), fm1 = f(x, m1),
		m2 = l + coef * (r - l), fm2 = f(x, m2);
	FOR(i, 0, M)
	{
		if (fm1 < fm2)
		{
			r = m2;
			m2 = m1;
			fm2 = fm1;
			m1 = r - coef * (r - l);
			
			fm1 = f(x, m1);//
		}
		else
		{
			l = m1;
			m1 = m2;
			fm1 = fm2;
			m2 = l + coef * (r - l);
			
			fm2 = f(x, m2);//
		}
	}
	return f(x, (l + r) / 2);
}

db fAB()
{
	double l = 0, r = h;
	
	const db coef = (-1 + sqrt(5)) / 2;
	const int M = 47;
	db m1 = r - coef * (r - l), fm1 = fBC(m1),
		m2 = l + coef * (r - l), fm2 = fBC(m2);
	FOR(i, 0, M)
	{
		if (fm1 < fm2)
		{
			r = m2;
			m2 = m1;
			fm2 = fm1;
			m1 = r - coef * (r - l);
			
			fm1 = fBC(m1);//
		}
		else
		{
			l = m1;
			m1 = m2;
			fm1 = fm2;
			m2 = l + coef * (r - l);
			
			fm2 = fBC(m2);//
		}
	}
	return fBC((l + r) / 2);
	
}


void solve()
{
	cin >> h >> a >> b >> c >> va >> vb >> vc;
	
	cout << fAB() << "\n";
}


int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int t;
	cin >> t;
	while(t--)
		solve();
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3820kb

input:

2
10 3 4 3 1 1 1
21 5 12 4 4 3 4

output:

14.142135623730951
8.750000000000000

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 210ms
memory: 3872kb

input:

10000
60522 14575 36426 79445 48772 90081 33447
90629 3497 47202 7775 94325 63982 4784
68417 2156 31932 35902 95728 78537 23857
30739 86918 29211 39679 38506 63340 86568
61868 60016 87940 96263 24593 1449 36991
90310 23355 77068 11431 8580 91757 49218
74934 94328 63676 29355 96221 99080 95922
31545 ...

output:

3.329500973126874
3.127387405727989
2.406279072474765
3.230771222357278
66.089547619093295
4.221960867080583
2.077557307407373
13.350847342148525
4.077427101679749
7.162318243909162
4.234664115125492
1.470864692147083
11.046488792123466
0.970222097745816
3.360088278626117
5.661612179733453
4.8966236...

result:

ok 10000 numbers