码迷,mamicode.com
首页 > 其他好文 > 详细

(简单) CF 44D Hyperdrive,数学。

时间:2015-10-09 23:02:47      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:

  In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that‘s why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, n - 1 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention.

Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That‘s why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of s hyperyears in s years).

When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make n - 2 identical to it ships with a hyperdrive and send them to other n - 2 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new n - 2 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues.

However the hyperdrive creators hurried to spread the news about their invention so much that they didn‘t study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy!

Your task is to find the time the galaxy will continue to exist from the moment of the ships‘ launch from the first planet.

  很长的题目,然而并不难。。。

  题目就是从1发出N-1个火箭,然后到达一颗星之后那颗星再发出N-2颗,然后问第一次碰撞的时间。

  然后对于第一代火箭,也就是1发出的,一定不会碰撞,然后对于第二代火箭,一定不会和第一代碰撞,因为三角形两边之和大于第三边。

  但是第二代火箭会和第二代碰撞,所以枚举两个发出第二代火箭的点就好了。。。

代码如下:

技术分享
// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ████━████   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━

// Author        : WhyWhy
// Created Time  : 2015年10月09日 星期五 21时51分18秒
// File Name     : A.cpp

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

const int MaxN=5005;

struct Point
{
    double x,y,z;
}P[MaxN];

int N;

double dist(const Point &a,const Point &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));
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    double minn=1e100;

    scanf("%d",&N);
    for(int i=1;i<=N;++i)
        scanf("%lf %lf %lf",&P[i].x,&P[i].y,&P[i].z);
    for(int i=2;i<=N;++i)
        for(int j=i+1;j<=N;++j)
            minn=min(minn,dist(P[1],P[i])+dist(P[1],P[j])+dist(P[i],P[j]));
    printf("%.10f\n",minn/2.0);
    
    return 0;
}
View Code

 

(简单) CF 44D Hyperdrive,数学。

标签:

原文地址:http://www.cnblogs.com/whywhy/p/4865303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!