2019 ICPC Asia Nanjing Regional K. Triangle
题目:在直角坐标系中给定 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的更多相关文章
- 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 ... 
- Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
		题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ... 
- The 2019 ICPC Asia Shanghai Regional Contest H  Tree Partition  k、Color Graph
		H题意: 给你一个n个节点n-1条无向边构成的树,每一个节点有一个权值wi,你需要把这棵树划分成k个子树,每一个子树的权值是这棵子树上所有节点权值之和. 你要输出这k棵子树的权值中那个最大的.你需要让 ... 
- 2019 ICPC Asia Taipei-Hsinchu Regional  Problem K Length of Bundle Rope  (贪心,优先队列)
		题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ... 
- 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的长 ... 
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
		题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ... 
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
		题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ... 
- 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 ... 
- 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 ... 
随机推荐
- (七)javac编译
			文章目录 1.基本格式 2.目标路径 2.1 缺省项 2.2 指定路径 2.2.1 全路径 2.2.2 相对路径 3.源文件 3.1 无第三方库 3.1.1 基本方法 3.1.2 添加目录 3.1.3 ... 
- rem1
			<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ... 
- day4-01 流程控制
			目录 一.if语法 1.什么是if? 2.语法结构 2.1.if 条件: 2.2.if...else: 2.3.if...elif...else: 2.4.if嵌套 二.循环结构 2.1 什么是循环结 ... 
- python自带的IDLE编译器,听说大神都用这个(附python下载安装教程)
			python这两年这么火,学的人越来越多,小伙伴们都用什么编译器了? 今天教大家安装python并熟悉python自带的编译器IDLE. 第一步,进入python官网https://www.pytho ... 
- Netty学习篇④-心跳机制及断线重连
			心跳检测 前言 客户端和服务端的连接属于socket连接,也属于长连接,往往会存在客户端在连接了服务端之后就没有任何操作了,但还是占用了一个连接:当越来越多类似的客户端出现就会浪费很多连接,netty ... 
- VirtualBox6安装CentOS7设置静态IP
			安装virtualbox后安装centos7, 这里就不在赘述了, 网上有很多教程 先关闭虚拟机, 按照如下设置配置网络 这里需要使用双网卡, 我们在开启第二个网卡, 如下所示 之后开启虚拟机, 进行 ... 
- 如何让elemengUI中的表格组件相同内容的单元格自动合并
			1. 前言 这两天在工作中遇到这样一个需求:将某个Excel中的数据在页面上以表格形式展示出来,并且尽量保持数据层级与Excel中一致.在原始Excel文件中,对每一行相同的数据都进行了合并,使得数据 ... 
- 实现 call、apply、bind
			实现 call.apply.bind 在之前一篇文章写了这三个参数的区别,但是其实面试更常考察如何实现.其实所有的原生函数的 polyfill 如何实现,只需要考虑 4 点即可: 基本功能 原型 th ... 
- day7-字符串格式化
			msg='i am %s my hobby is %s' % ('lhf','alex') # # %代表标识,固定格式 s代表传入的为字符串,该字符串可接受任何类型 # # %d ,只能接收数字 p ... 
- win7/win10系列的office安装与激活
			Windows系列电脑安装office傻瓜式教程 一. 下载与安装 下载 (1).所需工具:迅雷 下载链接:http://xl9.xunlei.com/ 显示界面如下,点击“立即下载”即可,然后 ... 
