Submission #1000732


Source Code Expand

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author RiaD
 */

#include <iostream>
#include <fstream>

#include <iostream>


#include <cmath>
#include <tuple>


#include <string>
#include <stdexcept>

#ifndef SPCPPL_ASSERT
	#ifdef SPCPPL_DEBUG
		#define SPCPPL_ASSERT(condition) \
		if(!(condition)) { \
			throw std::runtime_error(std::string() + #condition + " in line " + std::to_string(__LINE__) + " in " + __PRETTY_FUNCTION__); \
		}
	#else
		#define SPCPPL_ASSERT(condition)
	#endif
#endif



template <typename T, typename SquareT = T>
struct Point2D {
	T x, y;

	Point2D(): x(0), y(0) {
	}

	Point2D(T x, T y): x(x), y(y) {
	}

	SquareT squaredDist() const {
		return static_cast<SquareT>(x) * x + static_cast<SquareT>(y) * y;
	}

	auto dist() const -> decltype(sqrt(this->squaredDist())) {
		return sqrt(squaredDist());
	}

	double angle() const {
		return atan2(y, x);
	}

	Point2D& operator-=(const Point2D& rhs) {
		x -= rhs.x;
		y -= rhs.y;
		return *this;
	}

	Point2D& operator+=(const Point2D& rhs) {
		x += rhs.x;
		y += rhs.y;
		return *this;
	}

	Point2D& operator*=(T rhs) {
		x *= rhs;
		y *= rhs;
		return *this;
	}

	Point2D& operator/=(T rhs) {
		x /= rhs;
		y /= rhs;
		return *this;
	}

	T& operator[](size_t i) {
		if (i == 0) {
			return x;
		}
		if (i == 1) {
			return y;
		}
		SPCPPL_ASSERT(false);
	}

	const T& operator[](size_t i) const {
		if (i == 0) {
			return x;
		}
		if (i == 1) {
			return y;
		}
		SPCPPL_ASSERT(false);
	}

	template <typename U, typename V = U>
	Point2D<U, V> as() {
		return {U(x), U(y)};
	}

	Point2D normalized() const {
		static_assert(std::is_floating_point<T>::value, "only implemented for floating point types");
		return *this / dist();
	}

	Point2D rotated(double angle) const {
		static_assert(std::is_floating_point<T>::value, "only implemented for floating point types");
		double co = cos(angle);
		double si = sin(angle);
		return Point2D(x * co - y * si, x * si + y * co);
	}
};

template <typename T, typename S>
Point2D<T, S> operator+(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return Point2D<T, S>(lhs.x + rhs.x, lhs.y + rhs.y);
}

template <typename T, typename S>
Point2D<T, S> operator-(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return Point2D<T, S>(lhs.x - rhs.x, lhs.y - rhs.y);
}

template <typename T, typename S>
Point2D<T, S> operator*(const Point2D<T, S>& lhs, T rhs) {
	return Point2D<T, S>(lhs.x * rhs, lhs.y * rhs);
}

template <typename T, typename S>
Point2D<T, S> operator*(T lhs, const Point2D<T, S>& rhs) {
	return Point2D<T, S>(lhs * rhs.x, lhs * rhs.y);
}

template <typename T, typename S>
Point2D<T, S> operator/(const Point2D<T, S>& lhs, T rhs) {
	return Point2D<T, S>(lhs.x / rhs, lhs.y / rhs);
}

template <typename T, typename S>
S operator*(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return static_cast<S>(lhs.x) * rhs.y - static_cast<S>(rhs.x) * lhs.y;
}

template <typename T, typename S>
S operator%(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return static_cast<S>(lhs.x) * rhs.x + static_cast<S>(lhs.y) * rhs.y;
}

template <typename T, typename S>
bool operator==(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return lhs.x == rhs.x && lhs.y == rhs.y;
}

template <typename T, typename S>
bool operator!=(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) {
	return !(lhs == rhs);
}

struct LexicograficallyLess {
	template <typename T, typename S>
	bool operator()(const Point2D<T, S>& lhs, const Point2D<T, S>& rhs) const {
		return std::tie(lhs.x, lhs.y) < std::tie(rhs.x, rhs.y);
	};
};

template <typename T, typename S>
struct LessByAngle {
	explicit LessByAngle(const Point2D<T>& center): center(center) {
	}

	bool operator() (Point2D<T, S> lhs, Point2D<T, S> rhs) {
		lhs -= center;
		rhs -= center;
		if (upper(lhs) != upper(rhs)) {
			return upper(rhs);
		}
		return lhs * rhs > 0;
	}
private:
	bool upper(const Point2D<T>& point) {
		return point.y > 0 || (point.y == 0 && point.x > 0);
	}
	Point2D<T, S> center;
};

template <typename T, typename S>
double distance_to_segment(const Point2D<T, S>& point, const Point2D<T, S>& b, const Point2D<T, S>& c) {
	static_assert(std::is_floating_point<T>::value, "only implemented for floating point types");
	auto ba = b - point;
	auto ca = c - point;
	if ((ba - ca) % ba >= 0 && (ca - ba) % ca >= 0) {
		return fabs(ba * ca) / (ca - ba).dist();
	}
	return std::min(ba.dist(), ca.dist());
};

template <typename T, typename S>
double distance_to_line(const Point2D<T, S>& point, const Point2D<T, S>& b, const Point2D<T, S>& c) {
	static_assert(std::is_floating_point<T>::value, "only implemented for floating point types");
	auto ba = b - point;
	auto ca = c - point;
	return fabs(ba * ca) / (ca - ba).dist();
};

#include <vector>


#include <iterator>


/**
* Support decrementing and multi-passing, but not declared bidirectional(or even forward) because
* it's reference type is not a reference.
*
* It doesn't return reference because
* 1. Anyway it'll not satisfy requirement [forward.iterators]/6
*   If a and b are both dereferenceable, then a == b if and only if *a and
*   b are bound to the same object.
* 2. It'll not work with reverse_iterator that returns operator * of temporary which is temporary for this iterator
*
* Note, reverse_iterator is not guaranteed to work  now too since it works only with bidirectional iterators,
* but it's seems to work at least on my implementation.
*
* It's not really useful anywhere except iterating anyway.
*/
template <typename T>
class IntegerIterator: public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {
public:
	explicit IntegerIterator(T value): value(value) {

	}

	IntegerIterator& operator++() {
		++value;
		return *this;
	}

	IntegerIterator operator++(int) {
		IntegerIterator copy = *this;
		++value;
		return copy;
	}

	IntegerIterator& operator--() {
		--value;
		return *this;
	}

	IntegerIterator operator--(int) {
		IntegerIterator copy = *this;
		--value;
		return copy;
	}

	T operator*() const {
		return value;
	}

	bool operator==(IntegerIterator rhs) const {
		return value == rhs.value;
	}

	bool operator!=(IntegerIterator rhs) const {
		return !(*this == rhs);
	}

private:
	T value;
};

template <typename T>
class IntegerRange {
public:
	IntegerRange(T begin, T end): begin_(begin), end_(end) {
		SPCPPL_ASSERT(begin <= end);
	}

	IntegerIterator<T> begin() const {
		return IntegerIterator<T>(begin_);
	}

	IntegerIterator<T> end() const {
		return IntegerIterator<T>(end_);
	}

private:
	T begin_;
	T end_;
};

template <typename T>
class ReversedIntegerRange {
	typedef std::reverse_iterator<IntegerIterator<T>> IteratorType;
public:
	ReversedIntegerRange(T begin, T end): begin_(begin), end_(end) {
		SPCPPL_ASSERT(begin >= end);
	}

	IteratorType begin() const {
		return IteratorType(IntegerIterator<T>(begin_));
	}

	IteratorType end() const {
		return IteratorType(IntegerIterator<T>(end_));
	}

private:
	T begin_;
	T end_;
};

template <typename T>
IntegerRange<T> range(T to) {
	return IntegerRange<T>(0, to);
}

template <typename T>
IntegerRange<T> range(T from, T to) {
	return IntegerRange<T>(from, to);
}

template <typename T>
IntegerRange<T> inclusiveRange(T to) {
	return IntegerRange<T>(0, to + 1);
}

template <typename T>
IntegerRange<T> inclusiveRange(T from, T to) {
	return IntegerRange<T>(from, to + 1);
}

template <typename T>
ReversedIntegerRange<T> downrange(T from) {
	return ReversedIntegerRange<T>(from, 0);
}

template <typename T>
ReversedIntegerRange<T> downrange(T from, T to) {
	return ReversedIntegerRange<T>(from, to);
}

template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from) {
	return ReversedIntegerRange<T>(from + 1, 0);
}

template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {
	return ReversedIntegerRange<T>(from + 1, to);
}


using namespace std;

class TaskB {
public:
	void solve(std::istream& in, std::ostream& out) {
		using P = Point2D<double>;
		vector<P> p(3);
		for (int i: range(3)) {
			in >> p[i].x >> p[i].y;
		}

		vector<double> dist(3);
		for (int i: range(3)) {
			dist[i] = (p[i] - p[(i + 1) % 3]).dist();
		}

		vector<double> angles(3);


		auto angle = [&](double c, double b, double a) {
			return acos((-c * c + a * a + b * b)/2/a/b);
		};
		for (int i: range(3)) {
			angles[i] = angle(dist[i], dist[(i + 1) % 3], dist[(i + 2) % 3]);
		}


		double ans = 0;
		for (int i: range(3)) {
			//cerr << dist[i] << ' ' << angles[i % 3] << endl;
			double r = 2 + 1 / tan(angles[(i + 1) % 3] / 2.0) + 1 / tan(angles[(i + 2) % 3] / 2.0);
			r = dist[i] / r;
			ans = max(ans, r);
		}

		out << ans << "\n";

	}
};


int main() {
	std::ios_base::sync_with_stdio(false);
	TaskB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
	out << std::fixed;
	out.precision(20);
	solver.solve(in, out);
	return 0;
}

Submission Info

Submission Time
Task B - Inscribed Bicycle
User riadwaw
Language C++14 (GCC 5.4.1)
Score 500
Code Size 9327 Byte
Status AC
Exec Time 3 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 3 ms 384 KB
001.txt AC 2 ms 256 KB
002.txt AC 2 ms 256 KB
003.txt AC 2 ms 256 KB
004.txt AC 2 ms 256 KB
005.txt AC 3 ms 256 KB
006.txt AC 2 ms 256 KB
007.txt AC 2 ms 256 KB
008.txt AC 2 ms 256 KB
009.txt AC 3 ms 256 KB
010.txt AC 2 ms 256 KB
011.txt AC 2 ms 256 KB
012.txt AC 3 ms 256 KB
013.txt AC 3 ms 256 KB
014.txt AC 2 ms 256 KB
015.txt AC 2 ms 256 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 3 ms 256 KB