ICPC Asia Urumqi 2017 G. The Mountain

All as we know, a mountain is a large landform that stretches above the surrounding land in a limited area. If we as the tourists take a picture of a distant mountain and print it out, the image on the surface of paper will be in the shape of a particular polygon.

From mathematics angle we can describe the range of the mountain in the picture as a list of distinct points, denoted by (x1,y1)(x_1,y_1)(x1​,y1​) to (xn,yn)(x_n,y_n)(xn​,yn​). The first point is at the original point of the coordinate system and the last point is lying on the xxx-axis. All points else have positive y coordinates and incremental xxx coordinates. Specifically, all x coordinates satisfy 0=x1<x2<x3<...<xn0 = x_1 < x_2 < x_3 < ... < x_n0=x1​<x2​<x3​<...<xn​. All yyy coordinates are positive except the first and the last points whose yyy coordinates are zeroes.

The range of the mountain is the polygon whose boundary passes through points (x1,y1)(x_1,y_1)(x1​,y1​) to (xn,yn)(x_n,y_n)(xn​,yn​) in turn and goes back to the first point. In this problem, your task is to calculate the area of the range of a mountain in the picture.

Input

The input has several test cases and the first line describes an integer t(1≤t≤20)t (1 \le t \le 20)t(1≤t≤20) which is the total number of cases.

In each case, the first line provides the integer n(1≤n≤100)n (1 \le n \le 100)n(1≤n≤100) which is the number of points used to describe the range of a mountain. Following nnn lines describe all points and the iii-th line contains two integers xix_ixi​ and yi(0≤xi,yi≤1000)y_i (0 \le x_i, y_i \le 1000)yi​(0≤xi​,yi​≤1000) indicating the coordinate of the iii-th point.

Output

For each test case, output the area in a line with the precision of 666 digits.

样例输入复制

3
3
0 0
1 1
2 0
4
0 0
5 10
10 15
15 0
5
0 0
3 7
7 2
9 10
13 0

样例输出复制

1.000000
125.000000
60.500000

题目来源

ACM-ICPC 2017 Asia Urumqi

#include <bits/stdc++.h>

#define pre(i,x,n) for(int i=x;i<=n;i++)

#define rep(i,n,x) for(int i=n;i>=x;i--)

#define ll long long

using namespace std;

struct node

{

   double x,y;

}p[100010];

int main()

{

     int t,n;

     scanf("%d",&t);

     while(t--)

     {

        scanf("%d",&n);

        double ans=0;

        pre(i,1,n)

        {

            scanf("%lf%lf",&p[i].x,&p[i].y);

            if(i==1)

               ans+=p[i].x*p[i].y/2.0;

            else if(i==n)

               ans+=p[i-1].y*(p[i].x-p[i-1].x)/2.0;

            else

               ans+=(p[i].y+p[i-1].y)*(p[i].x-p[i-1].x)/2.0;

        }

        printf("%.6lf\n",ans);

     }

     return 0;

}

 

### 2024 ICPC Asia Regional Information #### 赛事概述 国际大学生程序设计竞赛(International Collegiate Programming Contest, ICPC)是一项全球性的编程比赛,旨在促进计算机科学教育并培养团队合作精神。每年的亚洲区域赛吸引了来自多个国家和地区的学生参与[^1]。 #### 时间安排 通常情况下,ICPC亚洲区域赛会在每年秋季举行预选赛,并于冬季举办现场决赛。具体到2024年的赛事时间表尚未公布,但可以参考往届的时间节点来推测大致的日程安排[^3]。 #### 参赛资格 参赛队伍一般由三名在校本科生组成,在指导教师的带领下完成一系列算法挑战题目。每支队伍需通过线上选拔赛获得参加线下总决赛的机会。对于有兴趣报名的同学来说,建议关注所在学校的通知以及官方渠道发布的最新消息[^4]。 #### 报名方式 各高校会组织内部选拔活动以组建代表队;成功入围者将统一注册成为正式选手。需要注意的是,不同赛区可能有不同的截止日期和特殊要求,因此务必提前做好准备并按时提交所需材料[^2]。 #### 备战指南 为了更好地迎接即将到来的比赛,可以从以下几个方面着手准备: - **学习基础知识**:深入理解数据结构、图论、动态规划等核心概念; - **练习历年真题**:熟悉各类题型及其解法模式; - **加强协作能力**:提高沟通效率,学会分工合作解决问题; - **保持良好心态**:面对高强度训练时不急不躁,调整好心理状态。 ```python def prepare_for_icpc(): study_fundamentals() practice_past_papers() enhance_teamwork_skills() maintain_positive_attitude() prepare_for_icpc() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值