Submission #1001315


Source Code Expand

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define EPS (1e-12)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, int> DI;

double calc_dist(int x1, int y1, int x2, int y2){
	double res = (sqrt)((x1 - x2) * (x1 - x2) + (y1 - y2)*(y1 - y2));
	return res;
}

double calc_area(double a, double b, double c){
	double s = (a + b + c) / 2.;
	double res = sqrt(s * (s - a) * (s - b) * (s - c));

	return res;
}

double calc_cos(double a, double b, double c){
	double res = (-a*a + b*b + c*c) / 2. / b / c;
	return res;
}

double calc_sin(double a, double b, double c, int i){
	double s = calc_area(a, b, c);
	double res = 2.* s;
	switch(i){
		case 0: res /= b; res /= c; break;
		case 1: res /= c; res /= a; break;
		case 2: res /= a; res /= b; break;
	} // end switch;

	return res;
}

double calc_half_cos(double cos){
	return sqrt((1. + cos) / 2.);
}

double calc_half_sin(double cos){
	return sqrt((1. - cos) / 2.);
}

double calc_half_inv_tan(double cos){
	return sqrt((1. + cos) / (1. - cos));
}

double calc_term_plus(double cos){
	return sqrt(1. + cos);
}

double calc_term_minus(double cos){
	return sqrt(1. - cos);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x[3] = {0};
	int y[3] = {0};
	rep (i, 3) cin >> x[i] >> y[i];
	DI l[3];
	rep (i, 3){
		l[i].first = calc_dist(x[i], y[i], x[(i+1)%3], y[(i+1)%3]);
		l[i].second = i;
	} // end rep
	sort(l, l+3);

	double s = calc_area(l[0].first, l[1].first, l[2].first);
	double a = l[2].first;
	double b = l[1].first;
	double c = l[0].first;

	double min_r = 0.;
	double max_r = 2.* s / (a + b + c);

	double min_cos = calc_cos(l[0].first, l[1].first, l[2].first);
	double half_min_cos = calc_half_cos(min_cos); 
	double half_min_sin = calc_half_sin(min_cos);

	double mid_cos = calc_cos(l[1].first, l[2].first, l[0].first);
	double half_mid_cos = calc_half_cos(mid_cos);
	double half_mid_sin = calc_half_sin(mid_cos);


	double min_term_plus = calc_term_plus(min_cos);
	double min_term_minus = calc_term_minus(min_cos);
	double mid_term_plus = calc_term_plus(mid_cos);
	double mid_term_minus = calc_term_minus(mid_cos);

	double res = 0.;
	while(abs(max_r - min_r) > EPS){
		double mid_r = (min_r + max_r) / 2.;
//		cerr << "mid_r: " << mid_r << endl;
	
		if (mid_r * (min_term_plus*mid_term_minus + mid_term_plus*min_term_minus + 2.*min_term_minus*mid_term_minus) 
			< a*min_term_minus*mid_term_minus + EPS){
			res = max(res, mid_r);
			min_r = mid_r;
		}else{
			max_r = mid_r;
		} // end if
	} // end while

	printf("%.12lf\n", res);

	return 0;
}

Submission Info

Submission Time
Task B - Inscribed Bicycle
User ty70
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2731 Byte
Status AC
Exec Time 2 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 18
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 2 ms 256 KB
001.txt AC 2 ms 256 KB
002.txt AC 2 ms 384 KB
003.txt AC 2 ms 256 KB
004.txt AC 2 ms 256 KB
005.txt AC 2 ms 384 KB
006.txt AC 2 ms 256 KB
007.txt AC 2 ms 384 KB
008.txt AC 2 ms 256 KB
009.txt AC 2 ms 256 KB
010.txt AC 2 ms 256 KB
011.txt AC 2 ms 256 KB
012.txt AC 2 ms 384 KB
013.txt AC 2 ms 256 KB
014.txt AC 2 ms 384 KB
015.txt AC 2 ms 256 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 2 ms 256 KB