首页 > 其他 > 详细

HDU 3132 Taunt Exposure Estimation(数学)

时间:2014-11-05 23:10:40      阅读:391      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3132


Problem Description
The brave knights bubuko.com,布布扣 of Camelot are constantly exposed to French taunting while assaulting the castle occupied by the French. Consequently, the taunting to which they are exposed varies with their distance from the castle during their assault, as well as variations in French taunting activity. We need to estimate the total amount of taunting that they are exposed to during a certain time period. Unfortunately, we only have access to a set of measurements at random times — we do not have a continuous reading — and, because of flaws in our archaic equipment, the measurements of taunting occur at unpredictable intervals. 

The total amount of taunting will be given by the integral of the taunting intensity during the time period, as held in the observation data file. The amount of random noise, though, is fairly high, so that a simple trapezoid-rule integration is all that is merited.

bubuko.com,布布扣

 

Input
  • A single number, n, specifying the number of data points in the file
  • n pairs of floating point numbers (given in increasing x order), separated by a comma — in other words, a CSV file that could be input for a spreadsheet program [the first number is the x coordinate (time specification), the second is the y coordinate (the radiation reading)]
  •  

    Output
    A single line of text giving the first and last x values (with two digits to the right of the decimal point), and the computed integral (with four digits to the right of the decimal point), in the fashion shown below (which reflects the data shown in the graph):

    0.00 to 365.25: 2099.8021

    [A reasonable value for the given input, (shown in the graph above), since the values range around 5 3/4, and 365.25 * 5.75 gives 2100.1875.]
     

    Sample Input
    9 0.0000, 0.5176 0.9869, 1.000 1.596, 1.114 2.370, 1.006 2.904, 0.8481 3.506, 0.5760 3.996, 0.4775 5.004, 0.3945 6.283, 1.004
     

    Sample Output
    0.00 to 6.28: 4.7288
     

    Source

    题意:

    给出一系列的坐标,将坐标连成折线,求折线和到X轴围成的多边形的面积!


    PS:

    题意看懂了就是一道很简单的求面积的题!

    把图形分成多块梯形,用梯形面积公式求每块梯形的面积再加一下就好!


    代码如下:

    #include <cstdio>
    #include <cstring>
    const int maxn = 10017;
    double x[maxn], y[maxn];
    int main()
    {
    #define TT
    #ifndef TT
        freopen("in.txt", "r",stdin);
        freopen("out.txt", "w", stdout);
    #endif // TT
        int n;
        while(~scanf("%d",&n))
        {
            for(int i = 0; i < n; i++)
            {
                scanf("%lf,%lf",&x[i],&y[i]);
            }
            double s = 0;
            for(int i = 1; i < n; i++)
            {
                s+=(y[i]+y[i-1])*(x[i]-x[i-1])/2.0;//梯形
            }
            printf("%.2lf to %.2lf: %.4lf\n",x[0],x[n-1],s);
        }
        return 0;
    }
    


    HDU 3132 Taunt Exposure Estimation(数学)

    原文:http://blog.csdn.net/u012860063/article/details/40834649

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
    © 2014 bubuko.com 版权所有
    打开技术之扣,分享程序人生!