結果

問題 No.724 円と円の間の円
ユーザー ats5515ats5515
提出日時 2017-10-04 09:27:46
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 78,716 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-21 17:47:11
合計ジャッジ時間 1,367 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>
using namespace std;
string tos(int a) {
	string res = "";
	if (a == 0) {
		res = '0';
	}
	while (a > 0) {
		res = char((a % 10) + '0') + res;
		a /= 10;
	}
	return res;
}
int n, a, b;

double calcY(double x) {
	return sqrt(a*b - (4 * a*b*(x - ((double)(a + b) / 2))*(x - ((double)(a + b) / 2)) / ((a + b)*(a + b))));
}
double calcR(double x,double y) {
	return sqrt((x - a)*(x - a) + y*y) - a;
}
double dst(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int main() {

	cin >> n >> a >> b;
	//cout << setprecision(15) << 4 * a*b*(b - a) / (double)((((double)n*n - 2 * n)* (b - a)*(b - a)) + (a + b)*(a + b)) << endl;
	double u;
	double d;
	double m;
	double x;
	double y;
	double t;
	double r;
	if(n % 2 == 0){
		u = a + b;
		d = 2 * a;
		while(u - d > 1e-9) {
			m = (u + d) * 0.5;
			t = calcY(m);
			if (t > calcR(m, t)) {
				d = m;
			}
			else {
				u = m;
			}
		}
		x = (u + d)*0.5;
		y = calcY(x);
	}
	else {
		x = a + b;
		y = 0;
	}
	n = (n - 1) / 2;
	r = calcR(x, y);
	while (n--) {
		u = x;
		d = 0;
		
		while (u - d > 1e-9) {
			m = (u + d) * 0.5;
			t = calcY(m);
			if (dst(m, t, x, y) > r + calcR(m, t)) {
				d = m;
			}
			else {
				u = m;
			}
		}
		x = (u + d)*0.5;
		y = calcY(x);
		r = calcR(x, y);
	}
	cout << r << endl;
	
	return 0;
}
0