The Tower

HDU - 6559

The Tower shows a tall tower perched on the top of a rocky mountain. Lightning strikes, setting the building alight, and two people leap from the windows, head first and arms outstretched. It is a scene of chaos and destruction.*

There is a cone tower with base center at (0, 0, 0), base radius r and apex (0, 0, h). At time 0 , a point located at (x0x0, y0y0, z0z0) with velocity (vxvx, vyvy, vzvz). What time will they collide? Here is the cone tower.

Input

The first line contains testcase number TT (TT ≤ 1000), For each testcase the first line contains spaceseparated real numbers rr and hh (1 ≤ rr, hh ≤ 1000) — the base radius and the cone height correspondingly.

For each testcase the second line contains three real numbers x0x0, y0y0, z0z0 (0 ≤ |x0x0|, |y0y0|, z0z0 ≤ 1000). For each testcase the third line contains three real numbers vxvx, vyvy, vzvz (1 ≤ v2xvx2 + v2yvy2 + v2zvz2 ≤ 3 × 106106). It is guaranteed that at time 0 the point is outside the cone and they will always collide.

Output

For each testcase print Case ii : and then print the answer in one line, with absolute or relative error not exceeding 10−610−6

Sample Input

2
1 2
1 1 1
-1.5 -1.5 -0.5
1 1
1 1 1
-1 -1 -1

Sample Output

Case 1: 0.3855293381
Case 2: 0.5857864376

题意:在三维空间中,给你一个底面在XOY面的圆锥,底面圆的圆心在原点。又给定一个动点的初始坐标,以及他的三个坐标轴方向的分速度,请计算出何时动点撞击到圆锥。

思路:我们设撞击的时间为t,那么我们可以根据三个方向的速度获得t时的坐标(x,y,z) 又因为碰到了圆锥面

所以根据这个剖视图可以得到图中的nowr,在根据x2+y2=nowr^2 可以得出 一个关于t的一元二次方程,求解判断哪个根符合条件,并且输出小的那一个即可。

具体的方程可以见这个群友的公式:

聚聚的博客连接:https://www.cnblogs.com/Dillonh/p/11196418.html

其实直接输出方程较小的那个根就是答案,具体为什么我还不太清楚。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
typedef long double ld;
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
int t;
gbtb;
cin >> t;
ld x, y, z, r, h, vx, vy, vz;
repd(cas, 1, t) {
cin >> r >> h;
cin >> x >> y >> z;
cin >> vx >> vy >> vz;
ld a = (vx * vx + vy * vy - r * r * vz * vz / h / h);
ld b = (2.0 * x * vx + 2.0 * y * vy - r * r * (2.0 * z * vz - 2.0 * h * vz) / h / h);
ld c = x * x + y * y - r * r * (h * h + z * z - 2.0 * h * z) / h / h;
ld g1 = -b - sqrt(b * b - 4.0 * a * c);
g1 /= 2.0 * a;
cout << "Case " << cas << ": ";
cout << fixed << setprecision(7) << g1 << endl;
}
return 0;
} inline void getInt(int *p)
{
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
} else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

The Tower HDU - 6559 (解析几何)的更多相关文章

  1. 2018 ccpc吉林 The Tower

    传送门:HDU - 6559 题意 在一个三维空间,给定一个点和他的三维速度,给定一个圆锥,问这个点最早什么时候能撞上圆锥. 题解 本来一直想着怎么求圆锥的方程,然后....队友:这不是二分吗!然后问 ...

  2. dp --- hdu 4939 : Stupid Tower Defense

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. HDU 4939 Stupid Tower Defense(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4939 解题报告:一条长度为n的线路,路上的每个单元格可以部署三种塔来给走在这条路上的敌人造成伤害,第一 ...

  4. hdu 5779 Tower Defence

    题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...

  5. Hdu 2971 Tower

    Description Alan loves to construct the towers of building bricks. His towers consist of many cuboid ...

  6. HDU 1329 Hanoi Tower Troubles Again!(乱搞)

    Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...

  7. hdu 4779 Tower Defense (思维+组合数学)

    Tower Defense Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  8. HDU计算机学院大学生程序设计竞赛(2015’12)The Magic Tower

    Problem Description Like most of the RPG (role play game), “The Magic Tower” is a game about how a w ...

  9. HDU 4779:Tower Defense

    Tower Defense Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)T ...

随机推荐

  1. 【ABAP系列】SAP ABAP DATA - COMMON PART

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP DATA - ...

  2. 纹理特征描述之灰度差分统计特征(平均值 对比度 熵) 计算和比较两幅纹理图像的灰度差分统计特征 matlab代码实现

    灰度差分统计特征有: 平均值:​ 对比度:​ 熵:​ i表示某一灰度值,p(i)表示图像取这一灰度值的概率 close all;clear all;clc; % 纹理图像的灰度差分统计特征 J = i ...

  3. 英特尔®oneAPI简介及动手实验研讨会召集令

    Intel Developer Zone 2019年超级计算大会英特尔正式发布了oneAPI软件行业计划及其beta产品,在上篇文章中我们已为您介绍了oneAPI的基本含义,本文将继续为您介绍oneA ...

  4. 华为服务器IBMC批量巡检代码

    selenium需要下载Chrome驱动webdriver,具体下载的版本根据自己的谷歌浏览器版本进行下载,然后将下载好的驱动webdriver放到自己python解释器同级目录中即可,下载地址htt ...

  5. 【VS开发】ATL辅助COM组件开发

    有些时候在程序的编写过程中我们会跨语言写一些东西,比如在C#中使用到C++,这个时候COM的出现就很好的解决了这一问题,我们如何来创建并且编写COM组件呢? 一.首先:创建一个ATL项目,如下图所示: ...

  6. ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】

    题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...

  7. 【Python】if __name__ == '__main__' 含义解析

    相信大家在看别人的python程序时,可能会在大部分的程序后看到标题这段代码,这里解释下它的意义.总的来说,这句代码的作用就是既能保证当前的.py文件直接运行,也能保证其可以作为模块被其他.py文件导 ...

  8. better-scroll踩坑合集

    better-scroll踩坑合集:https://www.jianshu.com/p/6338a8033281

  9. MySQL-复杂查询及条件-起别名-多表查询-04

    目录 基本查询语句及方法 测试数据创建 创建数据库与表 插入表记录数据 数据展示 常见结果排版 另一种结果排版 \G 简单查询语句的书写与执行顺序 查询语句书写 执行顺序 科普-- 起别名 写法 可以 ...

  10. 【IntelliJ IDEA】快捷键

    1.System.out.println();的快捷方法 sout然后Alt+Enter或者直接点 2.idea上 重写父类方法的快捷键 Ctrl+O之后,在弹出的上面选择要重写的方法 3.idea ...