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. F. Clique in the Divisibility Graph DP

    http://codeforces.com/contest/566/problem/F F. Clique in the Divisibility Graph time limit per test ...

  2. 开发工具~nuget配置本地源

    我们在本地部署了自己的nuget服务器,有时可以需要用到nuget restore命令去恢复包包,它会从下面的nuget.config里读你的配置源信息,就是在这里,我们要把内测的nuget服务器路径 ...

  3. Oracle中文乱码,字符集问题处理

    1. 右键计算机,选择属性,增加环境变量 NLS_LANG:SIMPLIFIED CHINESE_CHINA.ZHS16GBK 2.进入注册表,依次单击HKEY_LOCAL_MACHINE --> ...

  4. 什么是JavaScript

    来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=30&cid= JavaScript是一种松散类型的客户端脚本语言,在用户浏览器中执 ...

  5. 结合源码看nginx-1.4.0之nginx内存管理详解

    目录 0. 摘要 1. nginx内存结构设计 2. nginx内存数据结构 3. nginx内存管理原理 4. 一个简单的内存模型 5. 小结 6. 参考资料 0. 摘要 内存管理,是指软件运行时对 ...

  6. LeetCode Min Stack 最小值栈

    题意:实现栈的四个基本功能.要求:在get最小元素值时,复杂度O(1). 思路:链表直接实现.最快竟然还要61ms,醉了. class MinStack { public: MinStack(){ h ...

  7. [C++讨论课] 课堂记录(一)

    今天第一次参加c++讨论课,记录下了各组同学的展示的问题或者解决方法,也有一些知识点上的内容,供以后复习参考. 1.常量指针和指针常量问题 常量指针:指向常量的指针,例如const int *p =  ...

  8. keycode对应表

    keycode对应表 keycode    8 = BackSpace 回格keycode    9 = Tab keycode   12 = Clearkeycode   13 = Enter 回车 ...

  9. HTML之基本语法(段落标签、标题标签、空格标签、换行标签、图片标签和图片的基本属性)

    一.HTML标签 所谓的HTML的标签就是发明者认为定义好的一些单词,就相当于我们汉语中的字 二.HTML的语法 语法就是用来定义这些“字”应该如何解析或者书写的规则 三.常见标签及基本语法 1.人为 ...

  10. guruguru

    6576: guruguru 时间限制: 1 Sec  内存限制: 128 MB提交: 28  解决: 12[提交] [状态] [讨论版] [命题人:admin] 题目描述 Snuke is buyi ...