Algorithm increases 12-1 triangle time limit: 1.0s memory limit: 256.0MB The problem is described as a point in two-dimensional space design a structure, on the basis of which a structure for the triangle design. Separate functions are designed to calculate the perimeter, area, center, and centroid of the triangle. Enter three points to output the perimeter, area, Circumcenter, and center of gravity of the triangles that comprise these three points. The result retains 2 digits after the decimal point. The output of the sample output corresponds to the example input above.
Cases:
Data size and convention the range of each number in the input data.
Example: Doule type represents data.
Topic Links:
http://lx.lanqiao.cn/problem.page?gpid=T415
Main topic:
Give the triangle three point coordinates
Calculate perimeter area Circumcenter center of gravity
Topic Ideas:
"Mathematical Formula"
You can bring in mathematical formulas.
Circumcenter
x = x/, y = y/
where = 2 (XA-XB) (YC-YB)-2 (YA-YB) (XC-XB)
x = (YC-YB) (xa^2+ya^2-xb^2-yb^2)-(YA-YB) (xc^2+yc^2-xb^2-yb^2)
y = (XA-XB) (xc^2+yc^2-xb^2-yb^2)-(XC-XB) (xa^2+ya^2-xb^2-yb^2)
Focus:
x= (XA+XB+XC)/3, y= (YA+YB+YC)/3
1 /****************************************************2 3 author:coolxxx4 Copyright by Coolxxx. All rights reserved.5 BLOG:http://blog.csdn.net/u0105682706 7 ****************************************************/8#include <bits/stdc++.h>9 #pragmaComment (linker, "/stack:1024000000,1024000000")Ten #defineABS (a) ((a) >0? ( A):(-(a))) One #defineLowbit (a) (a& (a)) A #defineSqr (a) ((a) * (a)) - #defineMem (A, B) memset (A,b,sizeof (a)) - Const Doubleeps=1e-8; the Const intj=10000; - Const intMod=1000000007; - Const intmax=0x7f7f7f7f; - Const DoublePi=3.14159265358979323; + Const intn=1004; - using namespacestd; +typedefLong LongLL; A DoubleAnss; at LL Aans; - intCas,cass; - intN,m,lll,ans; - class Point - { - Public: in Doublex, y; - }; to classTriangle + { - Public: the Point a,b,c; * Doubleaa,bb,cc,p; $ Triangle (Point i,point j,point k)Panax Notoginseng { -A=i,b=j,c=K; theAa=sqrt (Sqr (a.x-b.x) +SQR (a.y-b.y)); +Bb=sqrt (Sqr (a.x-c.x) +SQR (a.y-c.y)); ACc=sqrt (Sqr (b.x-c.x) +SQR (b.y-c.y)); thep= (AA+BB+CC)/2; + } - Doubleperimeter () $ { $ returnp+p; - } - DoubleArea () the { - returnsqrt (p* (P-AA) * (P-BB) * (P-cc));Wuyi } the Point circumcenter () - { Wu Point p; -p.x= (C.Y-B.Y) * (SQR (a.x) +sqr (A.Y)-sqr (b.x)-SQR (B.Y))-(A.Y-B.Y) * (SQR (c.x) +sqr (C.Y)-SQR (b.x)-Sqr (B.Y)); AboutP.x/=2* (a.x-b.x) * (C.Y-B.Y)-2* (A.Y-B.Y) * (c.x-b.x); $p.y= (a.x-b.x) * (SQR (c.x) +sqr (C.Y)-sqr (b.x)-SQR (B.Y))-(c.x-b.x) * (SQR (a.x) +sqr (A.Y)-SQR (b.x)-Sqr (B.Y)); -P.y/=2* (a.x-b.x) * (C.Y-B.Y)-2* (A.Y-B.Y) * (c.x-b.x); - returnp; - } A Point centroid () + { the Point p; -p.x= (a.x+b.x+c.x)/3; $p.y= (A.Y+B.Y+C.Y)/3; the returnp; the } the }; the intMain () - { in #ifndef Online_judge the //freopen ("1.txt", "R", stdin); the //freopen ("2.txt", "w", stdout); About #endif the inti,j,k,l; the intx, y, z the //for (scanf ("%d", &cass); cass;cass--) + //for (scanf ("%d", &cas), cass=1;cass<=cas;cass++) - //while (~scanf ("%s", s)) the //while (~scanf ("%d", &n))Bayi if(1) the { the Point a,b,c; -Cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y; - triangle P (a,b,c); theA=P.circumcenter (); theb=p.centroid (); theprintf"%.2lf\n", P.perimeter ()); theprintf"%.2lf\n", P.area ()); -printf"%.2LF%.2lf\n", A.X,A.Y); theprintf"%.2LF%.2lf\n", b.x,b.y); the } the return 0;94 } the /* the // the 98 // About */
View Code
Blue Bridge ADV-230 algorithm increases the 12-1 triangle "mathematical formula"