ACM-ICPC 2017 Asia Urumqi 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 (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
题目来源
//根据题意首尾的两个点都在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的更多相关文章
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 有关信息ACM/ICPC竞争环境GCC/G++叠插件研究记录的扩展
0.起因 有时.DFS总是比BFS受人喜爱--毕竟DFS简单粗暴,更,而有些东西BFS不要启动,DFS它似乎是一个可行的选择-- 但是有一个问题,DFS默认直接写入到系统堆栈.系统堆栈和足够浅,此时O ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)
挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...
- ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】
题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...
- 2019 ACM/ICPC North America Qualifier G.Research Productivity Index(概率期望dp)
https://open.kattis.com/problems/researchproductivityindex 这道题是考场上没写出来的一道题,今年看看感觉简单到不像话,当时自己对于dp没有什么 ...
随机推荐
- HDU 5883 F - The Best Path 欧拉通路 & 欧拉回路
给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为 ...
- 常用API(Object、String、StringBuffer、用户登陆注册)
常用API 今日内容介绍 u Object u String u StringBuilder 第1章 Java的API及Object类 在以前的学习过程中,我们都在学习对象基本特征.对象的使用以及对象 ...
- css:hover伪类的使用
:hover的使用,即当鼠标指针移入元素时,所做出的样式设置 示例一 <!DOCTYPE html> <html lang="en"> <head&g ...
- 【虚拟机-网络IP】如何开放 Azure 虚拟机 Ping 功能
前言 文章<使用 PsPing & PaPing 进行 TCP 端口连通性测试>中提到,ICMP 协议的数据包无法通过 Azure 的防火墙和负载均衡器,所以不能直接使用 Ping ...
- 简单案列完美搞定Mvc设计模式
一个小列子搞定Mvc模式,包括数据库以及如何提高用户体验度 1.首先来web.xml配置servlet的访问路径: <?xml version="1.0" encoding= ...
- ABC3D创客项目:风力小车
随着互联网.开源硬件.电子信息等技术成熟应用,以及创新教育的大力普及,创新正成为青少年生活中最热门的话题之一:尤其新兴的3D打印技术将创意者.生产者.消费者合三为一,成为创新教育的又一大助力,每个学生 ...
- codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)
题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...
- 剑指offer64 数据流中的中位数
priority_queue优先级队列,他的模板声明带有三个参数,priority_queue<Type, Container, Functional> Type 为数据类型, Conta ...
- SQL Server将列以分隔符分割后存到临时表
begin if object_id('tempdb..#t') is not null drop table #t; create table #t ( filepath ) ); declare ...
- 关于List的remove方法我遇到的坑
结果是下标越界异常,原因是remove方法的参数不是value,而是index 唉~~~ 年少轻狂啊