题意:就是求里面的六边形的每条边的距离
思路:直接求就好了(把题目标号的顺序读反了,保佑队友不杀之恩)
代码:
#include <set> #include <map> #include <queue> #include <stack> #include <math.h> #include <vector> #include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #define zero(a) fabs(a)<eps #define max( x, y ) ( ((x) > (y)) ? (x) : (y) ) #define min( x, y ) ( ((x) < (y)) ? (x) : (y) ) #define lowbit(x) (x&(-x)) #define debug(a) cerr<<#a<<"=="<<a<<endl typedef long long LL; const long double pi=acos(-1.0); const long double eps=1e-8; const int inf=0x3f3f3f3f; const LL linf=0x3f3f3f3f3f3f3f3f; using namespace std; #define zero(x) (((x)>0?(x):-(x))<eps) int sgn(long double x) { if(fabs(x) < eps)return 0; if(x < 0)return -1; else return 1; } struct point { long double x,y; point (){} point (long double _x,long double _y) { x=_x,y=_y; } }; struct Line { point a,b; Line(){} Line(point _a,point _b) { a=_a; b=_b; } }; struct circle { point o; long double r; void print() { printf(" center:(%.4Lf, %.4Lf) rad: %.4Lf ", o.x, o.y, r); } }; long double xmult(point p1,point p2,point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } point intersection(point u1,point u2,point v1,point v2) { point ret=u1; long double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x)) /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x)); ret.x+=(u2.x-u1.x)*t; ret.y+=(u2.y-u1.y)*t; return ret; } point intersection(Line u,Line v) { point ret=u.a; long double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x)) /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x)); ret.x+=(u.b.x-u.a.x)*t; ret.y+=(u.b.y-u.a.y)*t; return ret; } long double dist(point a,point b) { return (long double)sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } point circumcenter(point a,point b,point c) { Line u,v; u.a.x=(a.x+b.x)/2; u.a.y=(a.y+b.y)/2; u.b.x=u.a.x-a.y+b.y; u.b.y=u.a.y+a.x-b.x; v.a.x=(a.x+c.x)/2; v.a.y=(a.y+c.y)/2; v.b.x=v.a.x-a.y+c.y; v.b.y=v.a.y+a.x-c.x; return intersection(u,v); } point incenter(point a,point b,point c) { Line u,v; long double m,n; u.a=a; m=atan2(b.y-a.y,b.x-a.x); n=atan2(c.y-a.y,c.x-a.x); u.b.x=u.a.x+cos((m+n)/2); u.b.y=u.a.y+sin((m+n)/2); v.a=b; m=atan2(a.y-b.y,a.x-b.x); n=atan2(c.y-b.y,c.x-b.x); v.b.x=v.a.x+cos((m+n)/2); v.b.y=v.a.y+sin((m+n)/2); return intersection(u,v); } circle getNqc(point a, point b, point c) { long double C = dist(a, b); long double B = dist(a, c); long double A = dist(b, c); circle cir; cir.o.x = (A*a.x + B*b.x + C*c.x) / (A + B + C); cir.o.y = (A*a.y + B*b.y + C*c.y) / (A + B + C); cir.r = sqrt((A + B - C)*(A - B + C)*(-A + B + C) / (A + B + C)) / 2; return cir; } void intersection_line_circle(point c,long double r,point l1,point l2,point& p1,point& p2) { point p=c; long double t; p.x+=l1.y-l2.y; p.y+=l2.x-l1.x; p=intersection(p,c,l1,l2); t=sqrt(r*r-dist(p,c)*dist(p,c))/dist(l1,l2); p1.x=p.x+(l2.x-l1.x)*t; p1.y=p.y+(l2.y-l1.y)*t; p2.x=p.x-(l2.x-l1.x)*t; p2.y=p.y-(l2.y-l1.y)*t; } Line line[10]; int main() { int T; scanf("%d",&T); while(T--){ int p; long double t1,t2,t3; point A,B,C,I,P,N,M; cin>>p>>t1>>t2>>t3; A=point(0.0,0.0),B=point(t1,0),C=point(t2,t3); circle qwe=getNqc(A,B,C); I=qwe.o; point wo=circumcenter(A,B,C); long double wr=dist(A,wo); point a1,a2; intersection_line_circle(wo,wr,I,A,a1,a2); if(fabs(a1.x-A.x)<eps&&fabs(a1.y-A.y)<eps){ M=a2; } else{ M=a1; } intersection_line_circle(wo,wr,I,B,a1,a2); if(fabs(a1.x-B.x)<eps&&fabs(a1.y-B.y)<eps){ N=a2; } else{ N=a1; } intersection_line_circle(wo,wr,I,C,a1,a2); if(fabs(a1.x-C.x)<eps&&fabs(a1.y-C.y)<eps){ P=a2; } else{ P=a1; } point E,F,K,J,H,G; G=intersection(Line(A,C),Line(M,N)); H=intersection(Line(M,N),Line(C,B)); J=intersection(Line(C,B),Line(M,P)); K=intersection(Line(M,P),Line(A,B)); E=intersection(Line(A,B),Line(N,P)); F=intersection(Line(N,P),Line(A,C)); printf("%d %.4Lf %.4Lf %.4Lf %.4Lf %.4Lf %.4Lf ",p,dist(E,F),dist(F,G),dist(G,H),dist(H,J),dist(J,K),dist(K,E)); } return 0; } /* 3 1 3 2.5 3 1 1 2 1 1.732 */