zoj3728_Collision(简单计算几何)
来源:互联网 发布:淘宝店铺装修公司 编辑:程序博客网 时间:2024/05/29 02:39
///////////////////////////////////////////////////////////////////////////////////////////////////////
作者:tt2767
声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0
查看本文更新与讨论请点击:http://blog.csdn.net/tt2767
链接被删请百度: CSDN tt2767
///////////////////////////////////////////////////////////////////////////////////////////////////////
题解:这题看明白之后主要是套模板去算。
1.用点积(dot)去判断是否不经过圆
2.用叉积求出原点到直线的距离
3.两种情况:撞击后反弹 或者 不撞击
4.记得只保留3位小数
#include<sstream>#include<string>#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<math.h>#include <iterator>#include<map>#include <stack>#include<queue>#include<set>#include <list>#include<functional>#include<numeric>using namespace std;inline int lowbit(int x){ return x&(-x);}struct Point{ double x,y; Point(double x,double y):x(x),y(y){} Point(){}};typedef Point Vector;double cross(Vector a , Vector b){ return a.x*b.y-a.y*b.x;}double dot(Vector a , Vector b){ return a.x*b.x+a.y*b.y;}typedef long long int LL;const double eps = 1e-9;const int INF = 0x3f3f3f3f ;const long double PI = acos(0.0) * 2.0;const int N = 100009;int main(){ double Rm,R,r,x,y,vx,vy; while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)==7 ) { Point p(x,y); Vector s(0-x,0-y),v(vx,vy); Rm+=r; R+=r; double vel = sqrt(v.x*v.x+v.y*v.y); double d = fabs(cross(s,v))/vel; if(dot(s,v) < eps || d-R > eps) printf("0.000\n"); else if(d - Rm > eps) printf("%.3lf\n",2*sqrt(R*R-d*d)/vel); else printf("%lf\n",2*( sqrt(R*R-d*d) - sqrt(Rm*Rm-d*d) )/vel ); } return 0;}
0 0
- zoj3728_Collision(简单计算几何)
- poj1410 简单计算几何
- uva5984(简单计算几何)
- 计算几何简单模板
- Rectangles 简单几何计算
- POJ 2624 简单计算几何
- poj1269 简单的计算几何
- hdu 4097 简单计算几何
- POJ 1675 简单计算几何
- hdu 4998 简单计算几何
- HDU 5533 简单计算几何
- hdu 4643(简单计算几何)
- [hdu] 6167 简单计算几何
- POJ2318 计算几何简单题
- 简单介绍几个计算几何的资源
- 计算几何题目分类+简单解释
- hdu 2108 简单计算几何 判断凹凸
- Ural-1020. Rope(简单计算几何)
- DNA Consensus String
- Windows10专业版非升级安装过程
- LeetCode-Reverse Linked List
- strncpy 引起的思考,重新认识了strncpy这个函数
- python处理网页时的unicode编码问题
- zoj3728_Collision(简单计算几何)
- 初识JAVA
- Cocos2d-x 中的 CC_DLL
- Edit Distance
- spring-ioc
- LINUX 基本命令 参照用
- 2015.07.26 地点:北京 天气:晴
- 应用Session变量控制用户登录时间
- 1856 More is better