zoukankan      html  css  js  c++  java
  • sicily 1206 Stacking Cylinders 简单的几何计算

    1206. Stacking Cylinders

    Constraints

    Time Limit: 1 secs, Memory Limit: 32 MB

    Description

    Problem Cylinders (e.g. oil drums) (of radius 1 foot) are stacked in a rectangular bin. Each cylinder on an upper row rests on two cylinders in the row below. The cylinders in the bottom row rest on the floor and do not roll from their original positions. Each row has one less cylinder than the row below.

    epsfbox{p3498.eps}

    This problem is to write a program to compute the location of the center of the top cylinder from the centers of the cylinders on the bottom row. Computations of intermediate values should use double precision.

    Input

    The input begins with a line containing the count of problem instances, nProb , as a decimal integer, (1<=nProb<=1000) . This is followed by nProb input lines. An input line consists of the number, n , of cylinders on the bottom row followed by n floating point values giving the x coordinates of the centers of the cylinders (the y coordinates are all 1.0 since the cylinders are resting on the floor (y = 0.0 )). The value of n will be between 1 and 10 (inclusive). The distance between adjacent centers will be at least 2.0 (so the cylinders do not overlap) and at most 3.4 (so cylinders at level k cannot touch cylinders at level k - 2 ).

    Output

    The output for each data set is a line containing the problem number (1...nProb) , a colon, a space, the x coordinate of the topmost cylinder to 4 decimal places, a space and the y coordinate of the topmost cylinder to 4 decimal places (both x and y ROUNDED to the nearest digit).

    Note: To help you check your work, the x -coordinate of the center of the top cylinder should be the average of the x -coordinates of the leftmost and rightmost bottom cylinders.

    Sample Input

    5 
    4 1.0 4.4 7.8 11.2 
    1 1.0 
    6 1.0 3.0 5.0 7.0 9.0 11.0 
    10 1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 20.4 
    5 1.0 4.4 7.8 11.2 14.6
    

    Sample Output

    1: 6.1000 4.1607 
    2: 1.0000 1.0000 
    3: 6.0000 9.6603 
    4: 10.7000 15.9100 
    5: 7.8000 5.2143

       O         (11) 
      O O        (21 22)
    O  OO      (31 32 33)      
                 11是最上面,31是左下角,33是右下角。      
                 如果画得标准的话,中间四个圆心(11 21 22 32 )
            连起来会得到正方形(边长2222)            
    然后设31和x轴夹角A                  
     利用各种关系表示出11 31圆心的距离和11 33圆心的距离 
    发现  11-31=32-11 而31 33是已知的。。所以
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <iostream>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    int zu,cnt;
    double x,xo,yo,a[10000];
    int main()
    {
        scanf("%d",&zu);                              // cout<<"1"<<endl;
        for(int th=1;th<=zu;++th)
        {                                                
             scanf("%d",&cnt);                    
            for(int i=1;i<=cnt;++i)
                scanf("%lf",&a[i]);                // cout<<"1"<<endl;}
            sort(a+1,a+cnt+1);
            xo=a[1];
            yo=1;
            for(int i=2;i<=cnt;++i)
            {
                x=(a[1]+a[i])/2;
                yo+=sqrt(4-(x-xo)*(x-xo));
                xo=x;
            }  
            printf("%d: %.4lf %.4lf
    ",th,xo,yo);
        }                                                //     cout<<"1"<<endl;
        return 0;
    }
    。。
    



  • 相关阅读:
    Spring Security -- 添加图形验证码(转载)
    Spring Security -- 自定义用户认证(转载)
    pandas agg 后降低df表层
    判断是否有人跟踪车辆的方案
    格隆汇笔记-黄勇演讲
    Mac mysql 忘记root密码的解决方法
    sql 同步2个表中的一个字段数据
    Linux下配置用msmtp和mutt发邮件
    spark StructType的应用,用在处理mongoDB keyvalue
    Idea2018旗舰版破解方法
  • 原文地址:https://www.cnblogs.com/tinyork/p/3467463.html
Copyright © 2011-2022 走看看