20 May 2014


Problem Description

The 1st Annual Guangdong Collegiate Programming Contest (GDCPC) was held in Zhuhai Campus of Zhongshan(SunYat-Sen) University last year. And now we gather again for the 2nd 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 ith line contains two nonnegative integers Xi(0<=Xi<=10000),Yi(0<=Yi<=10000) which represent the coordinate of the ith 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.

Sample Input

1 4
3 4
2 7
3 9

Sample Output





//  main.cpp
//  浏览珠海校区
//  Created by Yeah on 13-7-15.
//  Copyright (c) 2013年 Yeah. All rights reserved.

#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int main()
    unsigned int T(0);
    cin >> T;
    while (T--)
        unsigned int N(0);
        cin >> N;
        vector<pair<unsigned int, unsigned int> > vec(N);
        for (unsigned int i(0); i != N; ++i)
            cin >> vec[i].first >> vec[i].second;
        double area(0);
        for (unsigned int i(0); i != N - 1; ++i)
            area += (vec[i + 1].second + vec[i].second) * (vec[i + 1].first - vec[i].first) * 0.5;
        cout << setiosflags(ios::fixed) << setprecision(1) << area << endl;
    return 0;
题目链接Sicily Online Judge ZSUCPC2004-1009

blog comments powered by Disqus