• bnuoj 4209 Triangle(计算几何)


    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4209

    题意:如题

    题解:公式直接计算,或者角平分线求交点

    【code1】:

     1 #include <iostream>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include<stdio.h>
     6 
     7 using namespace std;
     8 //定义点
     9 struct point
    10 {
    11     double x,y;
    12 };
    13 
    14 typedef struct point point;
    15 
    16 
    17 double fabs(double x)
    18 {
    19     return x<0?-x:x;
    20 }
    21 //定义直线
    22 struct line
    23 {
    24     point a,b;
    25 };
    26 typedef struct line line;
    27 
    28 //两点距离
    29 double distance(point p1,point p2)
    30 {
    31     return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    32 }
    33 //两直线求交点
    34 point intersection(line u,line v)
    35 {
    36     point ret=u.a;
    37     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))
    38     /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
    39     ret.x+=(u.b.x-u.a.x)*t;
    40     ret.y+=(u.b.y-u.a.y)*t;
    41     return ret;
    42 }
    43 
    44 point incenter(point a,point b,point c)
    45 {
    46     line u,v;
    47     double m,n;
    48     u.a=a;
    49     m=atan2(b.y-a.y,b.x-a.x);
    50     n=atan2(c.y-a.y,c.x-a.x);
    51     u.b.x=u.a.x+cos((m+n)/2);
    52     u.b.y=u.a.y+sin((m+n)/2);
    53     v.a=b;
    54     m=atan2(a.y-b.y,a.x-b.x);
    55     n=atan2(c.y-b.y,c.x-b.x);
    56     v.b.x=v.a.x+cos((m+n)/2);
    57     v.b.y=v.a.y+sin((m+n)/2);
    58     return intersection(u,v);
    59 }
    60 
    61 int main()
    62 {
    63     point a,b,c;
    64     scanf("%lf%lf",&a.x,&a.y);
    65     scanf("%lf%lf",&b.x,&b.y);
    66     scanf("%lf%lf",&c.x,&c.y);
    67     point d;
    68     d = incenter(a,b,c);
    69     if(fabs(d.x)<1e-6) d.x=0;
    70     if(fabs(d.y)<1e-6) d.y=0;
    71     printf("%.2lf %.2lf
    ",d.x,d.y);
    72     return 0;
    73 }

    【code2】:

     1 #include <iostream>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include<stdio.h>
     6 
     7 //using namespace std;
     8 //定义点
     9 struct point
    10 {
    11     double x,y;
    12 };
    13 
    14 double distance(point p1,point p2)
    15 {
    16     return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
    17 }
    18 
    19 int main()
    20 {
    21     point a,b,c;
    22     scanf("%lf%lf",&a.x,&a.y);
    23     scanf("%lf%lf",&b.x,&b.y);
    24     scanf("%lf%lf",&c.x,&c.y);
    25     point d;
    26     double ab = distance(a,b);
    27     double bc = distance(b,c);
    28     double ac = distance(a,c);
    29     d.x = (a.x*bc+b.x*ac+c.x*ab)/(ab+bc+ac);
    30     d.y = (a.y*bc+b.y*ac+c.y*ab)/(ab+bc+ac);
    31     printf("%.2lf %.2lf
    ",d.x,d.y);
    32     return 0;
    33 }
  • 相关阅读:
    dalvik浅析二:jni、so
    android apk壳
    prism4 StockTrader RI 项目分析一些体会
    PRISM ‘VS100COMNTOOLS’ not set. Cannot set the build environment
    安卓移动应用代码安全加固系统设计及实现
    手机游戏外挂技术研究与运用
    移动终端安全威胁与应对措施
    游戏软件反外挂技术方案的设计和安全解决方案
    网络安全等级保护 2.0 下的安全体系建设
    APP加密,ios代码混淆工具,虚拟化技术 适用于移动应用程序的虚拟化加密软件
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3361979.html
Copyright © 2020-2023  润新知