HDU 4617 Weapon
2015-11-13 01:04
387 查看
题意:有n个圆柱,如果存在两个圆柱相交,就输出Lucky,否则输出在任意两圆柱距离的最小值
算一下直线间的距离就OK
算一下直线间的距离就OK
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; struct P { double x, y, z; P(){} P(double _x, double _y, double _z){x = _x; y = _y; z = _z;} }; P operator - (P a, P b) {return P(a.x-b.x, a.y-b.y, a.z-b.z);} P cross(P a, P b) {return P(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);} double dot(P a, P b) {return a.x*b.x + a.y*b.y + a.z*b.z;} double dis(P a, P b) {return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) + (a.z - b.z)*(a.z - b.z));} double len(P a) {return sqrt(a.x*a.x + a.y*a.y + a.z*a.z);} struct Weapon { P p, s; double r; }w[32]; int n; double get_dis(P p1, P s1, P p2, P s2) { P s = cross(s1, s2); if(len(s) < eps) return len(cross(s1, p2 - p1)) / len(s1); return fabs(dot(p2 - p1, s)) / len(s); } bool solve() { double Min = 1e18; for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) { double d = get_dis(w[i].p, w[i].s, w[j].p, w[j].s); if(d < w[i].r + w[j].r + eps) return true; Min = min(Min, d - w[i].r - w[j].r); } printf("%.2f\n", Min); return false; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i < n; i++) { P b, c; scanf("%lf%lf%lf", &w[i].p.x, &w[i].p.y, &w[i].p.z); P a = w[i].p; scanf("%lf%lf%lf", &b.x, &b.y, &b.z); scanf("%lf%lf%lf", &c.x, &c.y, &c.z); w[i].s = cross(b - a, c - a); w[i].r = dis(a, b); } if(solve()) printf("Lucky\n"); } return 0; }
相关文章推荐
- js 批量移除steam游戏 移除用户凭证中免费获取的物品
- 超级楼梯
- 不容易系列之一
- 关于健身与健美
- sort
- UVA 11517 Exact Change (01背包)
- 【SAS】主成分分析 因子分析
- Number Sequence
- Android 中的 Service 全面总结
- OC中函数和方法的区别
- 获取交换机带宽超过阀值就报警
- Fibonacci Again
- Sublime3学习笔记
- 文字超过宽度显示省略号(js版)
- Balloon Comes!
- 人见人爱A^B
- OC中局部变量,全局变量和成员变量
- 3n+1数链问题
- gcc下的内联函数
- 【POJ2013】:Symmetric Order