zoukankan      html  css  js  c++  java
  • HDOJ_ACM_Dome of Circus

    Problem Description
    A travelling circus faces a tough challenge in designing the dome for its performances. The circus has a number of shows that happen above the stage in the air under the dome. Various rigs, supports, and anchors must be installed over the stage, but under the dome. The dome itself must rise above the center of the stage and has a conical shape. The space under the dome must be air-conditioned, so the goal is to design the dome that contains minimal volume.
    You are given a set of n points in the space; (xi, yi, zi) for 1 ≤ i ≤ n are the coordinates of the points in the air above the stage that must be covered by the dome. The ground is denoted by the plane z = 0, with positive z coordinates going up. The center of the stage is on the ground at the point (0, 0, 0).
    The tip of the dome must be located at some point with coordinates (0, 0, h) with h > 0. The dome must have a conical shape that touches the ground at the circle with the center in the point (0, 0, 0) and with the radius of r. The dome must contain or touch all the n given points. The dome must have the minimal volume, given the above constraints.
     

    Input
    The input begins with an integer T. The next T blocks each represents a case. The first line of each case contains a single integer number n (1 ≤ n ≤ 10 000) - the number of points under the dome. The following n lines describe points with three floating point numbers xi, yi, and zi per line - the coordinates of i-th point. All coordinates do not exceed 1000 by their absolute value and have at most 2 digits after decimal point. All zi are positive. There is at least one point with non-zero xi or yi.
     

    Output
    For each case , write to the output file a single line with two floating point numbers h and r - the height and the base radius of the dome. The numbers must be precise up to 3 digits after decimal point.
     

    Sample Input
    3
    1
    1.00 0.00 1.00
    2
    1.00 0.00 1.00
    0.00 1.50 0.50
    3
    1.00 0.00 1.00
    0.00 1.50 0.50
    -0.50 -0.50 1.00
     

    Sample Output
    3.000 1.500
    2.000 2.000
    2.000 2.000
     

    Code
     1 #include <stdio.h>
     2 #include <math.h>
     3 #define N 10000
     4 struct Point
     5 {
     6     double x;
     7     double y;
     8     double z;
     9 }points[N + 5];
    10 int count;                    //everytime the number of points 
    11 double a[N + 5], b[N + 5];    //array a is r, array b is h 
    12 double getMaxH(double R)
    13 {
    14     double max, h;
    15     int i;
    16     max = 0;
    17     for (i = 1; i <= count; i++)
    18     {
    19         h = R * b[i] / (R - a[i]);
    20         if (h > max)
    21             max = h;
    22     }
    23     return max;
    24 }
    25 double f(double r, double h)
    26 {
    27     return r * r * h;
    28 }
    29 void main()
    30 {
    31     int i, n;
    32     double rlow, rhigh, rmid1, rmid2, max, h1, h2;
    33     max = 0;
    34     scanf("%d", &n);
    35     while (n--)
    36     {
    37         scanf("%d", &count);
    38         for (i = 1; i <= count; i++)
    39         {
    40             scanf("%lf %lf %lf", &points[i].x, &points[i].y, &points[i].z);
    41             a[i] = sqrt (points[i].x * points[i].x + points[i].y * points[i].y);
    42             b[i] = points[i].z;
    43             if (a[i] > max)
    44                 max = a[i];
    45         }
    46         rlow = max;
    47         rhigh = 1e6;
    48         while (rhigh - rlow >= 1e-6)
    49         {
    50             rmid1 = (rhigh + rlow) / 2;
    51             rmid2 = (rhigh + rmid1) / 2;
    52             h1 = getMaxH(rmid1);
    53             h2 = getMaxH(rmid2);
    54             if (f(rmid1, h1) < f(rmid2, h2))
    55                 rhigh = rmid2;
    56             else
    57                 rlow = rmid1;
    58         }
    59         printf("%.3lf %.3lf\n", h1, rmid1);
    60     }
    61 }
     

    Idea

    To begin with, u should reduce the X-Y-Z to X-Z, by using r = sqrt(x * x + y * y)

    Secondly, u should prove that when r increase, then v will reduce, then when r reduce, the v will reduce. Note, maybe u will get the value of the k, I try my best to use the value, but it's proved that it's no use.

    Last, u can use the trichotomy to divide the R. Note, u should count all the point so that u can get the max h, which means u contain all the points.

    Key point

    Firstly, u should write down the whole codes on the paper so that u can save the time to debug.

     
  • 相关阅读:
    『PyTorch』第二弹_张量
    大数据技术之_12_Sqoop学习_Sqoop 简介+Sqoop 原理+Sqoop 安装+Sqoop 的简单使用案例+Sqoop 一些常用命令及参数
    HBase 构建 Scanner 体系图解
    HBase 默认刷写文件 flush_compact.xml 注释解析
    Vim 命令、操作、快捷键全集
    10个在UNIX或Linux终端上快速工作的建议
    如何三招帮你排查Linux中的硬件问题
    介绍一些有趣的MySQL pager命令
    MySQL数据库select语句的使用方法
    能够在Linux系统中运行的5款大型耐玩游戏
  • 原文地址:https://www.cnblogs.com/chuanlong/p/2964903.html
Copyright © 2011-2022 走看看