QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112219#5677. Clarissa's Conical CannolisPetroTarnavskyi#AC ✓39ms4236kbC++171.9kb2023-06-10 18:36:372023-06-10 18:36:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-10 18:36:39]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:4236kb
  • [2023-06-10 18:36:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

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

const double EPS = 1e-9;

double d, s, r, o;
const double PI = acos(-1);

double g(double OA, double OX, double alpha, double XOA) {
	double XA = sqrt(OX * OX + OA * OA - 2 * OX * OA * cos(XOA));
	double sinOAX = OX * sin(XOA) / XA;
	assert(sinOAX > EPS && sinOAX < 1 - EPS);
	double OAX = asin(sinOAX);
	assert(OAX > alpha - EPS);
	return XA * (OAX - alpha);
}

double f(double b)
{
	double alpha = PI * d / s / 2;
	double OA = s - b;
	double OX = r;
	double cosBeta = OA * sin(alpha) / r;
	if (cosBeta > 1 - EPS) {
		return 0;
	}
	double beta = acos(cosBeta);
	double low = PI / 2 - alpha - beta, high = PI / 2 - alpha + beta;
	
	assert(low > -EPS && high < PI - alpha + EPS);
	
	FOR(it, 0, 747) {
		double m1 = low + (high - low) / 3, m2 = high - (high - low) / 3;
		if (g(OA, OX, alpha, m1) < g(OA, OX, alpha, m2)) {
			low = m1;
		}
		else {
			high = m2;
		}
	}
	return 2 * g(OA, OX, alpha, (low + high) / 2);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> d >> s >> r >> o;
	
	//cout << f(6.5) << endl;
	//return 0;
	
	double L = r, R = s - r;
	
	if(f(L) > o + EPS){
		cout << "-1.0\n";
		return 0;
	}
	if(f(R) < o - EPS){
		cout << "-2.0\n";
		return 0;
	}	
	
	FOR (i, 0, 474)
	{
		double m = (L + R) / 2;
		double res = f(m);
		if (res < o)
			L = m;
		else
			R = m;
	}
	cout << fixed << setprecision(1) << L - r << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 36ms
memory: 4124kb

input:

8.00 12.00 5.00 0.50

output:

1.5

result:

ok single line: '1.5'

Test #2:

score: 0
Accepted
time: 2ms
memory: 4016kb

input:

5.00 12.00 5.00 0.50

output:

-1.0

result:

ok single line: '-1.0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

11.00 12.00 5.00 0.50

output:

-2.0

result:

ok single line: '-2.0'

Test #4:

score: 0
Accepted
time: 36ms
memory: 4220kb

input:

7.00 12.00 3.00 0.90

output:

5.8

result:

ok single line: '5.8'

Test #5:

score: 0
Accepted
time: 2ms
memory: 4024kb

input:

8.50 12.00 3.00 0.90

output:

-2.0

result:

ok single line: '-2.0'

Test #6:

score: 0
Accepted
time: 2ms
memory: 4004kb

input:

10.00 12.00 3.00 0.70

output:

-2.0

result:

ok single line: '-2.0'

Test #7:

score: 0
Accepted
time: 31ms
memory: 4216kb

input:

5.50 12.00 3.50 0.30

output:

3.4

result:

ok single line: '3.4'

Test #8:

score: 0
Accepted
time: 32ms
memory: 4200kb

input:

7.00 12.00 3.50 0.70

output:

4.5

result:

ok single line: '4.5'

Test #9:

score: 0
Accepted
time: 39ms
memory: 4148kb

input:

8.50 12.00 3.50 0.70

output:

5.0

result:

ok single line: '5.0'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3944kb

input:

10.00 12.00 3.50 0.30

output:

-2.0

result:

ok single line: '-2.0'

Test #11:

score: 0
Accepted
time: 30ms
memory: 4160kb

input:

5.50 12.00 4.00 0.70

output:

2.5

result:

ok single line: '2.5'

Test #12:

score: 0
Accepted
time: 36ms
memory: 4220kb

input:

7.00 12.00 4.00 0.90

output:

3.5

result:

ok single line: '3.5'

Test #13:

score: 0
Accepted
time: 33ms
memory: 4124kb

input:

8.50 12.00 4.00 0.50

output:

3.8

result:

ok single line: '3.8'

Test #14:

score: 0
Accepted
time: 2ms
memory: 4032kb

input:

10.00 12.00 4.00 0.30

output:

-2.0

result:

ok single line: '-2.0'

Test #15:

score: 0
Accepted
time: 34ms
memory: 4016kb

input:

5.50 12.00 4.50 0.50

output:

1.1

result:

ok single line: '1.1'

Test #16:

score: 0
Accepted
time: 36ms
memory: 4140kb

input:

7.00 12.00 4.50 0.50

output:

2.1

result:

ok single line: '2.1'

Test #17:

score: 0
Accepted
time: 34ms
memory: 4196kb

input:

8.50 12.00 4.50 0.70

output:

2.9

result:

ok single line: '2.9'

Test #18:

score: 0
Accepted
time: 2ms
memory: 3948kb

input:

10.00 12.00 4.50 0.50

output:

-2.0

result:

ok single line: '-2.0'

Test #19:

score: 0
Accepted
time: 2ms
memory: 4064kb

input:

5.50 12.00 5.00 0.30

output:

-1.0

result:

ok single line: '-1.0'

Test #20:

score: 0
Accepted
time: 32ms
memory: 4236kb

input:

7.00 12.00 5.00 0.90

output:

1.3

result:

ok single line: '1.3'

Test #21:

score: 0
Accepted
time: 38ms
memory: 4032kb

input:

8.50 12.00 5.00 0.70

output:

1.8

result:

ok single line: '1.8'

Test #22:

score: 0
Accepted
time: 39ms
memory: 4004kb

input:

10.00 12.00 5.00 0.30

output:

2.0

result:

ok single line: '2.0'

Test #23:

score: 0
Accepted
time: 0ms
memory: 4076kb

input:

5.50 12.00 5.50 0.90

output:

-1.0

result:

ok single line: '-1.0'