Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define all(v) v.begin(), v.end()
- #define unq(v) sort(all(v)),(v).resize(unique(all(v))-v.begin())
- #define PI acos(-1.0) // 3.1415926535897932
- #define eps 1e-9
- #define radianof(x) x * (PI / 180.0)
- #define degreeof(x) x * (180.0 / PI)
- #define fixdouble(x) cout << fixed << setprecision(x)
- typedef double T;
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- struct PT{
- T x, y;
- PT(){}
- PT(T x, T y) : x(x), y(y) {}
- inline void input() {
- double _x, _y;
- scanf("%lf %lf", &_x, &_y);
- x = _x, y = _y;
- }
- inline void output() {
- printf("{%.1f, %.1f}\n", (double)x, (double)y);
- }
- inline bool operator == (const PT &p) const {
- return (abs(x - p.x) < eps && abs(y - p.y) < eps);
- }
- inline bool operator < (const PT &p) const {
- return ((x + eps < p.x) || (abs(x - p.x) < eps && y + eps < p.y));
- }
- } origin = PT(0, 0);
- //-----------operators-----------//
- inline PT operator + (const PT &u, const PT &v) {
- return PT(u.x + v.x, u.y + v.y);
- }
- inline PT operator - (const PT &u, const PT &v) {
- return PT(u.x - v.x, u.y - v.y);
- }
- inline PT operator * (const PT &u, const PT &v) {
- return PT(u.x * v.x - u.y * v.y, u.x * v.y + v.x * u.y);
- } // multiplying two complex numbers
- inline PT operator * (const PT &u, const T &d) {
- return PT(u.x * d, u.y * d);
- }
- inline PT operator * (const T &d, const PT &u) {
- return PT(u.x * d, u.y * d);
- }
- inline PT operator / (const PT &u, const T &d) {
- return PT(u.x / d, u.y / d);
- }
- //---------basic tools---------//
- T sqnorm(const PT &u) {
- return (u.x * u.x) + (u.y * u.y);
- }
- // double norm(const PT &u) {
- // return sqrt(sqnorm(u)); // |u|
- // }
- #define norm(u) sqrt(sqnorm(u))
- PT unit_vector(const PT &u) {
- assert(norm(u) > eps);
- return (u / (T)norm(u)); // u/|u|
- }
- T dot(const PT &u, const PT &v) {
- return (u.x * v.x) + (u.y * v.y);
- }
- T cross(const PT &u, const PT &v) {
- return (u.x * v.y) - (v.x * u.y);
- }
- double angle(const PT &u, const PT &v) { // u.v = |u||v|cos(theta)
- assert(norm(u) * norm(v) > eps);
- return acos(dot(u, v) / (norm(u) * norm(v)));
- }
- /* r = sqrt(x*x + y*y), theta = atan(y/x) [in radian] */
- PT toPolar(const PT &p){
- assert(abs(p.x) > eps);
- return PT(norm(p), atan(p.y/p.x)); // {r, theta}
- }
- /* x = r * cos(theta), y = r * sin(theta) [in radian] */
- PT toCartesian(const PT &p){
- return PT(p.x * cos(p.y), p.x * sin(p.y)); // {x, y}
- }
- PT extend(const PT &u, const PT &v, const T &len) {
- return v + unit_vector(v - u) * len; // parametric equation
- }
- PT projection(const PT &u, const PT &v, const PT &p) {
- assert(norm(v - u) > eps);
- return u + unit_vector(v - u) * (T)(dot(v - u, p - u) / norm(v - u));
- }
- PT rtt(const PT &piv, const PT &u, const double &theta) {
- return (u - piv) * toCartesian(PT(1.0, theta)) + piv;
- }
- //---------being a vector guy---------//
- /* area of Parallelogram abc and d = a+b */
- T TriArea(const PT &a, const PT &b, const PT &c){
- return cross(b - a, c - a); // + acw, - ccw, 0 linear
- }
- /* line ab to point c */
- int orientation(const PT &a, const PT &b, const PT &c) {
- T val = (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
- if(abs(val) < eps) return 0; // 0 linear
- return val > eps ? 1 : -1; // + ccw, - acw
- }
- /* point c is on segment ab or not */
- bool isOnSegment(const PT &a, const PT &b, const PT &c){
- if(abs(norm(b - a) - norm(c - a) - norm(b - c)) < eps) return true;
- return false;
- }
- /*line ab and line cd is parallel if ab X cd = 0 */
- bool ifParallel(const PT &a, const PT &b, const PT &c, const PT &d){
- return abs(cross(a - b, c - d)) < eps;
- }
- /*line ab and line cd is perpendicular if ab . cd = 0 */
- bool ifPerpendicular(const PT &a, const PT &b, const PT &c, const PT &d){
- return abs(dot(a - b, c - d)) < eps;
- }
- /* segment ab and segment cd intersect or not */
- bool isSegIntersect(const PT &a, const PT &b, const PT &c, const PT &d){
- return (orientation(a, b, c) != orientation(a, b, d)
- && orientation(c, d, a) != orientation(c, d, b));
- }
- PT LineIntersection(const PT &a, const PT &b, const PT &p, const PT &q){
- assert(abs(cross(b - a, p - q)) > eps);
- return a + (b - a) * cross(p - a, p - q) / cross(b - a, p - q);
- }
- PT _f;
- /* angular sort _f = arr[0] */
- bool CC(const PT &a, const PT &b){
- return (_f.x-a.x)*(_f.y-b.y)<(_f.x-b.x)*(_f.y-a.y);
- }
- bool CCW(PT &a,PT &b){
- return (_f.x-a.x)*(_f.y-b.y)>(_f.x-b.x)*(_f.y-a.y);
- }
- /* Radial Sort: _f = any extreme point of hull */
- bool ClockCmp(const PT &a, const PT &b){
- int val = orientation(_f, a, b);
- if(val == 0) return (sqnorm(a - _f) + eps) < sqnorm(b - _f);
- return val > 0;
- }
- bool AClockCmp(const PT &a, const PT &b){
- int val = orientation(_f, a, b);
- if(val == 0) return (sqnorm(a - _f) + eps) < sqnorm(b - _f);
- return val < 0;
- }
- //----------------------------------//
- int main()
- {
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- double x1, y1, x2, y2, x3, y3;
- while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3){
- PT A(x1, y1), B(x2, y2), C(x3, y3);
- PT midAB = (A + B)/2;
- PT rot_midAB = rtt(midAB, A, radianof(90));
- PT midAC = (A + C)/2;
- PT rot_midAC = rtt(midAC, A, radianof(90));
- PT center = LineIntersection(midAB, rot_midAB, midAC, rot_midAC);
- double r = norm(center - A);
- printf("(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2\n", (center.x > 0) ? '-' : '+',
- abs(center.x),
- (center.y > 0) ? '-' : '+',
- abs(center.y),
- r);
- double val = sqnorm(center) - r * r;
- printf("x^2 + y^2 %c %.3fx %c %.3fy %c %.3f = 0\n\n", (center.x > 0) ? '-' : '+',
- (abs(center.x * 2)),
- (center.y > 0) ? '-' : '+',
- (abs(center.y *2)),
- (val < 0) ? '-' : '+',
- abs(val));
- }
- #ifdef ERFANUL007
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement