游览珠海校区

游览珠海校区

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte

描述

       The 1^st Annual Guangdong Collegiate Programming Contest (GDCPC) was held in Zhuhai Campus of Zhongshan (Sun Yat-Sen) university last year. And now we gather again for the 2^nd GDCPC in the same wonderful place. After the contest, most of the participants will probably have a jaunt around the beautiful Campus.

       As you have seen, the main attraction of this place is the green hills surrounding. And a problem comes up now. What is the area of cross section of the hills?

       This range of hills contains peaks and valleys. So before calculating the area, we have to firstly scale and write down the coordinates of the turning points. In the following graph, 7 turning points of a hill are marked.



输入

The first line of the input is a positive integer T. T is the number of the test cases followed.

       The first line of each test cases contains only one positive integer N (1 <= N <= 1000) which represents the number of the turning points. Then N lines follow and the i^th line contains two nonnegative integers Xi (0 <= Xi <= 10000), Yi (0 <= Yi <= 10000) which represent the coordinate of the i^th turning point. It is assumed that the given turning points is in X-coordinate increasing order, i.e. Xi < Xj when I < j.

 

输出

       The output of the program should consist of one line of output for each test case. The output of each test case only contains one real number which represents the area of the cross section of the hills. The real numbers are rounded to one decimal digit. No redundant spaces are needed.


样例输入

2
2
1 4
3 4
2
2 7
3 9

样例输出

8.0
8.0


          本题是一个简单的数学几何题。题意是输入一些山的转折点的坐标,要求求出整座山的面积。因为数据是沿着 x 轴并且从左到右进行输入的,所以可以从每个转折点处分开,看成多个梯形组成,从而将梯形面积相加,便求出山的面积。

#include <stdio.h>
#include <math.h>

int main ()
{
    int w, z, i, j;
    double sum, x[10005], y[10005];
    scanf("%d",&w);
    while(w--)
    {
        sum = 0;
        scanf("%d",&z);
        for(i = 0; i < z; ++i)
            scanf("%lf %lf",&x[i],&y[i]);
        for(j = 1; j < z; ++j) ///对每个梯形求面积并算总和
            sum = sum + (y[j] + y[j-1]) * (x[j] - x[j-1])/2;
        printf("%.1f\n",sum);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值