博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 11796 Dog Distance 向量+相对运动
阅读量:4113 次
发布时间:2019-05-25

本文共 3404 字,大约阅读时间需要 11 分钟。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const int mod = 1000000007; const double eps = 1e-10; const int inf = 0x3f3f3f3f; const int big=50000; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x) , y(y) { } }; typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); } Vector operator - (Vector A, Vector B) { return Vector(A.x-B.x, A.y-B.y); } Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); } Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int dcmp(double x) { if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } bool operator == (const Point& a, const Point& b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } double Length(Vector A) { return sqrt(Dot(A, A)); } double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; } double Area2(Point A, Point B, Point C) { return Cross(B-A, C-A); } Vector Rotate(Vector A, double rad) { return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad) ); } Vector Normal(Vector A) { double L = Length(A); return Vector(-A.y/L, A.x/L); } Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { Vector u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(Point P, Point A, Point B) { Vector v1 = B-A, v2 = P - A; return fabs(Cross(v1,v2) / Length(v1)); } double DistanceToSegment(Point P, Point A, Point B) { if(A==B) return Length(P-A); Vector v1 = B - A, v2 = P - A, v3 = P - B; if(dcmp(Dot(v1, v2)) < 0) return Length(v2); else if(dcmp(Dot(v1, v3)) > 0) return Length(v3); else return fabs(Cross(v1, v2)) / Length(v1); } Point GetLineProjection(Point P, Point A, Point B) { Vector v = B - A; return A + v * ( Dot(v, P-A) / Dot(v, v) ); } bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; } bool OnSegment(Point p, Point a1, Point a2) { return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0; } double ConvexPolygonArea(Point* p, int n) { double area = 0; for(int i = 1; i < n-1; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]); return area / 2; } int numa,numb; Point a[55],b[55]; void input() { scanf("%d",&numa); scanf("%d",&numb); for(int i=1;i<=numa;i++) { scanf("%lf %lf",&a[i].x,&a[i].y); // printf("|||ai:%f %f\n",a[i].x,a[i].y); } for(int i=1;i<=numb;i++) { scanf("%lf %lf",&b[i].x,&b[i].y); // printf("|||ai:%f %f\n",b[i].x,b[i].y); } } void solve(int i) { double lena=0,lenb=0; for(int i=2;i<=numa;i++) lena+=Length(a[i]-a[i-1]); for(int i=2;i<=numb;i++) lenb+=Length(b[i]-b[i-1]); //printf("|||lena:%f lenb:%f\n",lena,lenb); Point sa=a[1],sb=b[1]; int pa=1,pb=1; double minn=inf,maxn=0; while(pa
分析:向量的运用,训练指南上讲的也很详细

转载地址:http://ptgsi.baihongyu.com/

你可能感兴趣的文章
微信小程序中使用npm过程中提示:npm WARN saveError ENOENT: no such file or directory
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
Vue项目中使用img图片和background背景图的使用方法
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>
HTTP和HttpServletRequest 要点
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
关于无线PCB中 中50欧姆的特性阻抗的注意事项
查看>>