UPC组队训练 G:The Mountain

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a17865569022/article/details/81913105

这里写图片描述

#include<bits/stdc++.h>
using namespace std;
struct node
{
    double x;
    double y;
}p[105];
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int n;scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lf %lf",&p[i].x,&p[i].y);
        double sum=0;
        for(int i=1;i<n-2;i++)
        {
            double temp1,temp2;
            temp1=min(p[i].y,p[i+1].y)*fabs(p[i].x-p[i+1].x);
            temp2=fabs(p[i].y-p[i+1].y)*fabs(p[i].x-p[i+1].x)/2;
            sum+=(temp1+temp2);
        }
        double s1=(p[1].x-p[0].x)*p[1].y/2;
        double s2=(p[n-1].x-p[n-2].x)*p[n-2].y/2;
        sum+=(s1+s2);
        printf("%.6lf\n",sum);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/a17865569022/article/details/81913105