题目:在直角坐标系中给定 p1,p2,p3构成三角形,给定p4可能在三角形边上也可能不在,

问能不能在三角形上找出p5,使得线段p4p5,平分三角形(p4必须在三角形上)。不能则输出-1.

思路:四个点,三条边,三条边的长度,和代码的数据一一对应存储。

①:不在三角形上

②:在三角形上

  ①在顶点上(两条线段上)

  ②不在顶点上(一条线段上)

    ①在中点

    ②不在中点

最麻烦的就是p4只存在于一条边上。

代码:

 #include<bits/stdc++.h>
using namespace std; const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
} double operator ^(const Point &b)const//叉积
{
return x*b.y - y*b.x;
} double operator *(const Point &b)const//点积
{
return x*b.x + y*b.y;
}
void transXY(double B)//绕原点旋转角度B(弧度值),后x,y的变化
{
double tx = x,ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) + ty*cos(B);
}
void read(double a,double b){
x = a; y = b;
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
}
pair<int,Point> operator &(const Line &b)const
{
//两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交
//只有第一个值为2时,交点才有意义
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((s-b.e)^(b.s-b.e)) == )
return make_pair(,res);//重合
else return make_pair(,res);//平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(,res);
}
void read(Point& a,Point& b){
s.x = a.x;
s.y = a.y;
e.x = b.x;
e.y = b.y;
}
};
bool OnSeg(Point& P,Line& L)//判断点在线段上
{
return
sgn((L.s-P)^(L.e-P)) == &&
sgn((P.x - L.s.x) * (P.x - L.e.x)) <= &&
sgn((P.y - L.s.y) * (P.y - L.e.y)) <= ;
}
//线长
inline double get_Ldis(Line& L){
return sqrt((L.s.x-L.e.x)*(L.s.x-L.e.x)+(L.s.y-L.e.y)*(L.s.y-L.e.y));
}
//两点长
inline double get_pdis(Point& a,Point& b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} inline void print(Line& L){
printf("%.12f %.12f\n",(L.s.x+L.e.x)/,(L.s.y+L.e.y)/);
} inline double fun(double n,double x1,double x2,double d){
return n*(x1-x2)/d + x2;
}
Point p[]; Line L[]; double d[];
inline void solve(Line& l,double m1,double m2,Point& p1,Point& p2,Point& p3,double d1,double d2,double d3){ double n;
double x,y;
if(m1==m2) {printf("%.12f %.12f\n",p1.x,p1.y); return;}
else if( m1 > m2){
n = (d1*d2)/(*m1);
x = fun(n,p1.x,p2.x,d1);
y = fun(n,p1.y,p2.y,d1);
}
else{
n = (d2*d3)/(*m2);
x = fun(n,p1.x,p3.x,d3);
y = fun(n,p1.y,p3.y,d3);
}
printf("%.12f %.12f\n",x,y);
} int main()
{ int T;
double m1,m2;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&p[].x,&p[].y,&p[].x,&p[].y,&p[].x,&p[].y,&p[].x,&p[].y);
L[].read(p[],p[]); L[].read(p[],p[]); L[].read(p[],p[]);
for(int i = ; i <= ; ++i) d[i] = get_Ldis(L[i]); if(OnSeg(p[],L[]) || OnSeg(p[],L[]) || OnSeg(p[],L[])){
if(OnSeg(p[],L[]) && OnSeg(p[],L[])){
print(L[]); continue;
}
if(OnSeg(p[],L[]) && OnSeg(p[],L[])){
print(L[]);continue;
}
if(OnSeg(p[],L[]) && OnSeg(p[],L[])){
print(L[]);continue;
}
if(OnSeg(p[],L[])){
m1 = get_pdis(p[],p[]);
m2 = d[] - m1;
solve(L[],m1,m2,p[],p[],p[],d[],d[],d[]);
continue;
}
if(OnSeg(p[],L[])){
m1 = get_pdis(p[],p[]);
m2 = d[] - m1;
solve(L[],m1,m2,p[],p[],p[],d[],d[],d[]);
continue;
}
if(OnSeg(p[],L[])){
m1 = get_pdis(p[],p[]);
m2 = d[] - m1;
solve(L[],m1,m2,p[],p[],p[],d[],d[],d[]);
continue;
}
printf("-1\n");
}
else printf("-1\n");
} return ;
}

2019 ICPC Asia Nanjing Regional K. Triangle的更多相关文章

  1. 2019 ICPC Asia Nanjing Regional

    2019 ICPC Asia Nanjing Regional A - Hard Problem 计蒜客 - 42395 若 n = 10,可以先取:6,7,8,9,10.然后随便从1,2,3,4,5 ...

  2. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  3. The 2019 ICPC Asia Shanghai Regional Contest H Tree Partition k、Color Graph

    H题意: 给你一个n个节点n-1条无向边构成的树,每一个节点有一个权值wi,你需要把这棵树划分成k个子树,每一个子树的权值是这棵子树上所有节点权值之和. 你要输出这k棵子树的权值中那个最大的.你需要让 ...

  4. 2019 ICPC Asia Taipei-Hsinchu Regional Problem K Length of Bundle Rope (贪心,优先队列)

    题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ...

  5. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  6. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  7. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  8. Gym - 101981A The 2018 ICPC Asia Nanjing Regional Contest A.Adrien and Austin 简单博弈

    题面 题意:一堆有n个石子,编号从1⋯N排成一列,两个人Adrien 和Austin玩游戏,每次可以取1⋯K个连续编号的石子,Adrien先手,谁不能取了则输 题解:k==1时,显然和n奇偶相关,当k ...

  9. 2019 ICPC Asia Xuzhou Regional

    目录 Contest Info Solutions A. Cat B. Cats line up C. <3 numbers E. Multiply F. The Answer to the U ...

随机推荐

  1. (乱入)FingerGesture

    偶然的机会遇到FingerGesture插件,此插件也有很多方便的功能,比如控制主相机查看模型以及缩放等功能,如Component-FingerGestures-Toolbox-Camera-Orbi ...

  2. Solr入门(一)

    一丶Solr入门1.Solr的启动Solr各版本下载老版本的时候,需要将war包放到tomcat中,现在只需解压,由于自带jetty容器,可以直接启动 [root@aaa bin]# ./solr s ...

  3. Pyhton网络爬虫之CrawlSpider

    一.什么是CrawlSpider? 在学习CrawlSpider之前如果我们想爬取某网站前100页的内容的话,我们可以使用的方法是通过Request模块手动发起请求,递归调用parse方法,写起来非常 ...

  4. 关于 mybatis 报invalid comparison: java.util.Arrays$ArrayList and java.lang.String异常

    今天碰到个问题,来记录下,希望可以帮助到大家 贴错误源码: 这是一个根据list集合的查找数据的 sql,在接收list的时候加了判断 list != ‘ ’ “”,引起了集合与Stirng类型的比较 ...

  5. Unity3d粒子特效:制作火焰效果

    效果 分析 真实的火焰效果,通常包括:火.火光.火星等组成部分,而火焰对周围环境的烘焙,可以通过灯光实现,如点光源. 针对火焰组成部分,我们可以创建对应的粒子系统组件,实现相应的效果,如下图所示: 1 ...

  6. 【重构】AndroidStudio中代码重构菜单Refactor功能详解

    代码重构几乎是每个程序员在软件开发中必须要不断去做的事情,以此来不断提高代码的质量.Android Stido(以下简称AS)以其强大的功能,成为当下Android开发工程师最受欢迎的开发工具,也是A ...

  7. SQL 中更新一个表的数据是从另外的表(或者自己本身的表)查询出来的

    模板1: update 表1 set  表1.字段1 = ( select 表1字段或者表2字段 from  表2 where  表1主键 = 表2外键 及其他条件 )  where 表1.字段 = ...

  8. C语言1博客作业04

    问题 答案 这个作业属于那个课程 C语言程序设计1 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/9770 我在这 ...

  9. [模板]tarjan——最后通牒

    这么久了我还是不会板子,你们随便笑话我吧. 再不会打我实在是无能为力了. 这篇博客写的像个智障一样...写它的目的就是自嘲? 才不是,为了方便查阅,因为我真的记不住. 对于割边,要存储该点入边的编号, ...

  10. NOIP模拟测试25

    这次考试后面心态爆炸了...发现刚了2h的T2是假的之后就扔掉了,草率地打了个骗分 T1只会搜索和m=0 最先做的T3,主要是发现部分分很多,当时第一眼看上去有87分(眼瞎了). 后来想了想,感觉一条 ...