UVA 10242 Fourth Point
2024-09-03 09:14:18
题意:给你平行四边形两条边的顶点,让你求第四个点。
思路:要找到俩边的公共点,然后向量运算。
AC代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//叉积
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//点积
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double len(){
return hypot(x, y);
}
double len2(){
return x * x + y * y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
}
Point operator + (const Point &b)const{
return Point (x + b.x, y + b.y);
}
Point operator * (const double &k)const{
return Point(x * k, y * k);
}
Point operator / (const double &k)const{
return Point(x / k, y / k);
}
};
int main()
{
double x1, x2, x3, x4, y1, y2, y3, y4;
Point p[], c;
while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4))
{
p[] = Point(x1,y1);
p[] = Point(x2,y2);
p[] = Point(x3,y3);
p[] = Point(x4,y4);
sort(p , p + );
if(p[] == p[])
{
c = p[] + p[] - p[];
}
if(p[] == p[])
{
c = p[] + p[] - p[];
}
if(p[] == p[])
{
c = p[] + p[] - p[];
}
printf("%.3f %.3f\n",c.x, c.y);
}
return ;
}
最新文章
- A couple of notes about .NET Framework 4.6 setup behaviors
- DX 系列之 ComboBoxEdit
- CSS3--overflow属性
- Echarts 地图(map)插件之 鼠标HOVER和tooltip自定义提示框
- libavcodec/dxva2.h:40:5: error: unknown type name &#39;IDirectXVideoDecoder&#39;
- UI进阶 多线程
- think straight系列读书笔记之《暗时间》
- bounds的深入研究
- 50道java线程面试题
- XML 从基础到精通
- address2line 定位 Android c++奔溃位置
- textarea高度随内容自适应
- idea 导eclipse项目
- var、let、const区别
- IDEA中debug启动tomcat报错。Error running t8:Unable to open debugger port(127.0.0.1:49225):java.net.BindException";Address alread in use:JVM_Bind";
- 初学spring boot 一
- Redis(2)---数据持久化
- oracle 之 基础操作
- Patterns for Asynchronous MVVM Applications: Commands
- seleniumWebdriver浏览器驱动信息汇总
热门文章
- HTML5: HTML5 Web 存储
- PHP-文件和目录操作
- 32. 持续集成简介及JDK、Tomcat、Jenkins环境搭建
- C++异常处理try、catch 没有finally
- .net报错大全
- ajax 通过回调函数获取异步数据
- activiti7从act_ge_bytearray表中查询资源文件并保存到桌面文件夹中
- MOV EAX,DWORD PTR SS:[EBP+8]
- Arcpy 遍历每一个要素新建要素类
- Failed! Error: Unknown error 1130