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 (x_1,y_1)(x1​,y1​) to (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 xx-axis. All points else have positive y coordinates and incremental xx coordinates. Specifically, all x coordinates satisfy 0 = x_1 < x_2 < x_3 < ... < x_n0=x1​<x2​<x3​<...<xn​. All yy coordinates are positive except the first and the last points whose yy coordinates are zeroes.

The range of the mountain is the polygon whose boundary passes through points (x_1,y_1)(x1​,y1​) to (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 \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 \le n \le 100)n(1≤n≤100) which is the number of points used to describe the range of a mountain. Following nn lines describe all points and the ii-th line contains two integers x_ixi​ and y_i (0 \le x_i, y_i \le 1000)yi​(0≤xi​,yi​≤1000) indicating the coordinate of the ii-th point.

Output

For each test case, output the area in a line with the precision of 66 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

//根据题意首尾的两个点都在x轴上,因此分成前后两个三角形和中间若干个梯形即可。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
int n,t;
const int N=;
struct Node{
int x,y;
}nod[N];
int main()
{
scanf("%d",&t);
double ans;
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d%d",&nod[i].x,&nod[i].y);
ans=;
for(int i=;i<n;i++){
ans+=(nod[i-].y+nod[i].y)*(nod[i].x-nod[i-].x)/2.0;
}
printf("%.6f\n",ans);
}
return ;
}

ACM-ICPC 2017 Asia Urumqi G. The Mountain的更多相关文章

  1. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  2. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  3. ACM-ICPC 2017 Asia Urumqi A. Coins

    Alice and Bob are playing a simple game. They line up a row of n identical coins, all with the heads ...

  4. ACM-ICPC 2017 Asia Urumqi:A. Coins(DP) 组合数学

    Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the head ...

  5. ACM-ICPC 2017 Asia Urumqi(第八场)

    A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...

  6. 有关信息ACM/ICPC竞争环境GCC/G++叠插件研究记录的扩展

    0.起因 有时.DFS总是比BFS受人喜爱--毕竟DFS简单粗暴,更,而有些东西BFS不要启动,DFS它似乎是一个可行的选择-- 但是有一个问题,DFS默认直接写入到系统堆栈.系统堆栈和足够浅,此时O ...

  7. ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)

    挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...

  8. ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】

    题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...

  9. 2019 ACM/ICPC North America Qualifier G.Research Productivity Index(概率期望dp)

    https://open.kattis.com/problems/researchproductivityindex 这道题是考场上没写出来的一道题,今年看看感觉简单到不像话,当时自己对于dp没有什么 ...

随机推荐

  1. GPIO的翻转操作方法

    STM32在进行IO翻转操作的时候可以使用以下方法:以PE.5为例 GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataB ...

  2. 洛谷P1057 传球游戏

    f[i][j]表示第i轮j拿到球的方案数 转移:f[i][j]=f[i-1][j+1] +f[i-1][j+-1].注意: 边界f[0][1]=1; 还有当j=1或N时 #include<ios ...

  3. Unity3d中3D Text对模型的穿透显示

    昨晚,好友在电话里问我在Unity3d中使用3D Text,不想让其穿透模型显示,即想让场景中的3D Text与模型有正确的遮挡关系,怎么解? 今早谷歌上查了查,明白了原因,因为3D Text的默认材 ...

  4. springBoot jpa 分页

    1.jap中有自带的分页方法 在dao层中使用 Page<LinkUrl> findAll(Pageable pageable); 2.在controller层 public List&l ...

  5. html5 02 随记

    HTML 02 全局通用属性  id  name  class  style 一. 图像标签 标签名:<img  /> 常用属性: Alt -- 代表图像的替代文字 作用: 当图片不显示的 ...

  6. Windows下Python多版本共存

    Windows下Python多版本共存 Python数据科学安装Numby,pandas,scipy,matpotlib等(IPython安装pandas) 0.0 因为公司项目,需要Python两个 ...

  7. 假如m是奇数,且m>=3,证明m(m² -1)能被8整除

    m是奇数,且m>=3 =>m可以用表达式2n-1,n>=2 =>m²-1 = (2n-1)²-1 =>m²-1 = 4n²-4n+1-1 =>m²-1 = 4n²- ...

  8. 中国各运营商(电信、联通、移动、铁通)IP地址段

    除此电信.联通.移动.铁通之外还有教育网.科技网.广电.长城.广电…… 表格下载: http://files.cnblogs.com/files/xiaohi/中国IP网段.zip 以上资料参考: h ...

  9. UVA11090 Going in Cycle (二分+判负环)

    二分法+spfa判负环.如果存在一个环sum(wi)<k*x,i=0,1,2...,k,那么每条边减去x以后会形成负环.因此可用spfa来判负环. 一般spfa判负环dfs最快,用stack次之 ...

  10. UVA 11925 Generating Permutations 生成排列 (序列)

    题意:要用一个有序的序列生成给定序列,操作有两种,一是交换前两个元素,二是把第一个元素移动到最后去. 思路有两种: 1.映射,把给定序列映射成有序的序列,然后按照同样的替换规则把有序的序列映射掉,然后 ...