POJ1673 ZOJ1776 三角形四心模板
POJ1673 题中所述点即为三角形的垂心,用向量法可以轻松证明。
垂心 重心 外心 均位于三角形的欧拉线上,且三者有线性关系,于是,求出重心和外心即可求得垂心。
重心就是三点的平均值,外心可以通过解方程的方法简单求得。
给出代码
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std; const double eps=1e-9; int cmp(double x)
{
if(fabs(x)<eps)return 0;
if(x>0)return 1;
else return -1;
} const double pi=acos(-1.0); inline double sqr(double x)
{
return x*x;
} struct point
{
double x,y;
point (){}
point (double a,double b):x(a),y(b){}
void input()
{
scanf("%lf%lf",&x,&y);
}
friend point operator +(const point &a,const point &b)
{
return point(a.x+b.x,a.y+b.y);
}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend bool operator ==(const point &a,const point &b)
{
return cmp(a.x-b.x)==0&&cmp(a.y-b.y)==0;
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator*(const double &a,const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
double norm()
{
return sqrt(sqr(x)+sqr(y));
}
}; point Triangle_Mass_Center(point a,point b,point c)
{
return(a+b+c)/3.;
} point CircumCenter(point p0,point p1,point p2)
{
point cp;
double a1=p1.x-p0.x,b1=p1.y-p0.y,c1=(a1*a1+b1*b1)/2.;
double a2=p2.x-p0.x,b2=p2.y-p0.y,c2=(a2*a2+b2*b2)/2.;
double d=a1*b2-a2*b1;
cp.x=p0.x+(c1*b2-c2*b1)/d;
cp.y=p0.y+(a1*c2-a2*c1)/d;
return cp;
}
point Orthocenter(point a,point b,point c)
{
return Triangle_Mass_Center(a,b,c)*3.0-CircumCenter(a,b,c)*2.0;
} point Innercenter(point a,point b,point c)
{
point cp;
double la,lb,lc;
la=(b-c).norm();
lb=(c-a).norm();
lc=(a-b).norm();
cp.x=(la*a.x+lb*b.x+lc*c.x)/(la+lb+lc);
cp.y=(la*a.y+lb*b.y+lc*c.y)/(la+lb+lc);
return cp;
} int main()
{freopen("t.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
point a,b,c;
a.input();b.input();c.input();
point ans=Orthocenter(a,b,c);
printf("%.4lf %.4lf\n",ans.x,ans.y);
}
return 0;
}
ZOJ1776 给定三角形求角平分线的交点(即内心)
内心坐标的公式如下。
首先证明这个结论:O是ABC内心的充要条件是:aOA+bOB+cOC=0 (均表示向量)
证明:OB=OA+AB,OC=OA+AC,代入aOA+bOB+cOC=0中得到:
AO=(bAB+cAC)/(a+b+c)
而|AC|=b,|AB|=c
所以AO=bc/(a+b+c) * (AB/|AB|+AC/|AC|)
而由平行四边形法则值(AB/|AB|+AC/|AC|)与BAC交角平分线共线
所以AO经过内心
同理BO,CO也经过内心,所以O为内心
反之亦然,就不证了
知道这个结论后
设ABC的坐标为:A(x1,y1),B(x2,y2),C(x3,y3) BC=a,CA=b,AB=c
内心为O(x,y)则有aOA+bOB+cOC=0(三个向量)
MA=(x1-x,y1-y)
MB=(x2-x,y2-y)
MC=(x3-x,y3-y)
则:a(x1-x)+b(x2-x)+c(x3-x)=0,a(y1-y)+b(y2-y)+c(y3-y)=0
∴x=(ax1+bx2+cx3)/(a+b+c),Y=(ay1+by2+cy3)/(a+b+c)
∴O((ax1+bx2+cx3)/(a+b+c),(ay1+by2+cy3)/(a+b+c))
代码如下
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<iomanip>
using namespace std; const double eps=1e-9; int cmp(double x)
{
if(fabs(x)<eps)return 0;
if(x>0)return 1;
else return -1;
} const double pi=acos(-1.0); inline double sqr(double x)
{
return x*x;
} struct point
{
long double x,y;
point (){}
point (long double a,long double b):x(a),y(b){}
void input()
{
char c;
x=y=0.0;
cin>>x>>c>>y;
}
friend point operator +(const point &a,const point &b)
{
return point(a.x+b.x,a.y+b.y);
}
friend point operator -(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
friend bool operator ==(const point &a,const point &b)
{
return cmp(a.x-b.x)==0&&cmp(a.y-b.y)==0;
}
friend point operator *(const point &a,const double &b)
{
return point(a.x*b,a.y*b);
}
friend point operator*(const double &a,const point &b)
{
return point(a*b.x,a*b.y);
}
friend point operator /(const point &a,const double &b)
{
return point(a.x/b,a.y/b);
}
long double norm()
{
return sqrt(sqr(x)+sqr(y));
}
}; point Triangle_Mass_Center(point a,point b,point c)
{
return(a+b+c)/3.;
} point CircumCenter(point p0,point p1,point p2)
{
point cp;
double a1=p1.x-p0.x,b1=p1.y-p0.y,c1=(a1*a1+b1*b1)/2.;
double a2=p2.x-p0.x,b2=p2.y-p0.y,c2=(a2*a2+b2*b2)/2.;
double d=a1*b2-a2*b1;
cp.x=p0.x+(c1*b2-c2*b1)/d;
cp.y=p0.y+(a1*c2-a2*c1)/d;
return cp;
}
point Orthocenter(point a,point b,point c)
{
return Triangle_Mass_Center(a,b,c)*3.0-CircumCenter(a,b,c)*2.0;
} point Innercenter(point a,point b,point c)
{
point cp;
long double la,lb,lc;
la=(b-c).norm();
lb=(c-a).norm();
lc=(a-b).norm();
cp.x=(la*a.x+lb*b.x+lc*c.x)/(la+lb+lc);
cp.y=(la*a.y+lb*b.y+lc*c.y)/(la+lb+lc);
return cp;
} int main()
{freopen("t.txt","r",stdin);
//freopen("1.txt","w",stdout);
int T;
while(cin>>T)
{ while(T--)
{
point a,b,c;
a.input();b.input();c.input();
point ans=Innercenter(a,b,c); cout<<"("<<int(a.x)<<","<<int(a.y)<<")";
cout<<"("<<int(b.x)<<","<<int(b.y)<<")";
cout<<"("<<int(c.x)<<","<<int(c.y)<<"):";
if(ans.x>eps)ans.x=floor(ans.x*10000)/10000.;
else ans.x=ceil(ans.x*10000)/10000.;
if(ans.y>eps)ans.y=floor(ans.y*10000)/10000.;
else ans.y=ceil(ans.y*10000)/10000.;
cout<<fixed<<setprecision(4);
cout<<"("<<ans.x<<","<<ans.y<<")"<<endl; }
}
return 0;
}
POJ1673 ZOJ1776 三角形四心模板的更多相关文章
- 牛客小白月赛5 E 面积 计算三角形面积模板 波尔约-格维也纳定理 匹克公式
链接:https://www.nowcoder.com/acm/contest/135/E来源:牛客网 题目描述 定义“最大生成图”:在M*N的点阵中,连接一些点形成一条经过所有点恰好一次的回路,且连 ...
- Naive and Silly Muggles (计算几何)
Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 记502 dp专练
趁着503的清早 我还算清醒把昨天老师讲的内容总结一下,昨天有点迷了 至使我A的几道题都迷迷糊糊的.(可能是我太菜了) 这道题显然是 数字三角形的变形 好没有经过认真思考然后直接暴力了 这是很不应该的 ...
- hdu 2202 最大三角形_凸包模板
题意:略 思路:直接套用凸包模板 #include <iostream> #include <cstdio> #include <cmath> #include & ...
- ACM模板(持续补完)
1.KMP #include<cstring> #include<algorithm> #include<cstdio> using namespace std; ...
- ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)
1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 177 Solved: 136[Submit][Status ...
- 用MathType编辑横三角形的方法
如果常常接触数学公式,你会发现同一个符号如果变换方向使用就可以代表不同的数学含义,这是非常常见的一种数学现象了.对于这种情况在数学公式编辑器中,我们可以使用不同的模板来进行编辑.比如横着的三角形符号, ...
- ytu 1058: 三角形面积(带参的宏 练习)
1058: 三角形面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 190 Solved: 128[Submit][Status][Web Boar ...
- uestc_retarded 模板
虽然这个队,以后再也没有了,但是他的模板,是永垂不朽的![误 #include <ext/pb_ds/priority_queue.hpp> __gnu_pbds::priority_qu ...
随机推荐
- JS 实现全屏预览 F11功能
老是不通过,没办法,只能是重新发布了,反正我就是杠上了,大大小小写过很多前端特效,当然也经常在网上copy或者修改人家的代码,我觉得也挺好的,为什么?!因为我想这样,你能怎么办,打我?少废话,直接上代 ...
- C语言学习7
结构体数组:实现简易通讯录 #include <stdio.h> #include <stdlib.h> #define NUM 3 struct person { ]; ]; ...
- 集训第四周(高效算法设计)A题 Ultra-QuickSort
原题poj 2299:http://poj.org/problem?id=2299 题意,给你一个数组,去统计它们的逆序数,由于题目中说道数组最长可达五十万,那么O(n^2)的排序算法就不要再想了,归 ...
- java-得到字符串中出现次数最最多的字符,并打印出字符以及出现次数
最近面试总被面试到,整理出几种方式(有参考别人的部分) /** * java一个字符串中出现次数最多的字符以及次数 * @param args */ public static void main(S ...
- Dijkstra算法C++实现总结
问题描述 求无负权图中点s到点t的最短凝聚力 备注 标准说法中,"缩短"/"松弛"(relax)操作是对边进行的.下面为了行文方便,将其拓展到点.即以下操作,其 ...
- 在fragment中获取activity的组件
在fragment中使用getActivity()即可获取activity的引用
- 博弈论入门题 kiki's game
Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...
- java 8种基本类型与对应的包装类
数据类型 包装类 字节长度 默认值 有效位 byte Byte 1 0 -128~127 short Short 2 0 -32768~32767 int Integer 4 0 -2^31-1~2^ ...
- 记一次调试python内存泄露的问题
转载:http://www.jianshu.com/p/2d06a1a01cc3 这两天由于公司需要, 自己编写了一个用于接收dicom文件(医学图像文件)的server. 经过各种coding-de ...
- Windows 2008 R2 SP1部署WSUS 3.0 SP2
1 实验环境 1)域: 域名为fengxja.com: 网段:192.168.0网段,不连接外网. 域功能级别和林功能级别为Windows server 2003模式. 2)DC服务器: 域控制器: ...