UVA11437 Triangle Fun
2021/11/15 23:12:24
本文主要是介绍UVA11437 Triangle Fun,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这是一道入门计算几何题,偏数学,和算法关系不大
我逛了一圈题解发现都是用的数学求法,这里我就用计算几何来水我第一篇洛谷题解
步骤:
1.求三等分点
2.求交点
3.叉积求面积
#include<iostream> #include<algorithm> #include<cmath> #include<math.h> #include<vector> using namespace std; //模板 #define x first #define y second typedef pair<double,double>PDD; PDD operator + (PDD A,PDD B) { return {A.x+B.x,A.y+B.y}; } PDD operator - (PDD A,PDD B) { return {A.x-B.x,A.y-B.y}; } PDD operator * (PDD A,double p) { return {A.x*p,A.y*p}; } PDD operator / (PDD A,double p) { return {A.x/p,A.y/p}; } PDD get_point(PDD B,PDD C) { PDD v1=B+(C-B)/3; return {v1.x,v1.y}; } double cross(PDD a,PDD b) { return a.x*b.y-a.y*b.x; } PDD getlineintersection(PDD p,PDD v,PDD q,PDD w) { auto u=p-q; double t=cross(w,u)/cross(v,w); return PDD{p.x+v.x*t,p.y+v.y*t}; } int main() { int n; cin>>n; while(n--) { PDD A,B,C,D,E,F; double x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2>>x3>>y3; A={x1,y1},B={x2,y2},C={x3,y3}; D=get_point(B,C); E=get_point(C,A); F=get_point(A,B); //求三等分点 PDD P,Q,R; P=getlineintersection(A,D-A,B,E-B); Q=getlineintersection(B,E-B,C,F-C); R=getlineintersection(C,F-C,A,D-A); //求交点 printf("%.0lf\n",cross(Q-P,R-P)/2); //叉积求面积 } return 0; }
这篇关于UVA11437 Triangle Fun的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?