A - Playground
My kid's school cleared a large field on their property recently to convert it into a playing area. The field is polygonal. The school administration decided to separate the field into two areas by building a straight picket fence between the area for the older kids and the area for the younger kids. The fence would go between two non-adjacent vertices of the polygonal field, and given the shape of the field, all such possible fences would lie strictly and entirely within the field.
Naturally,
the smaller of the two areas would go to the younger kids. So can you
help the school determine what the area of the smaller play-area would
be for different fence positions?
INPUT
The
first line contains 2 numbers N denoting the number of points in the
convex polygon and Q denoting the number of possible locations of
straight line fences.
The next N lines contain 2 integers each. The
ith line contains the integers xi yi denoting the coordinates of the ith
point of the polygon. The points are given in clockwise order.
The next Q lines contain 2 integers a b denoting that a straight line fence is to be drawn connecting a and b.
OUTPUT
Output
Q lines one corresponding to each query. For each query, output the
area of the smaller region for the corresponding query truncated to 1
decimal place. Always have 1 digit after the decimal place, so if the
answer is 1, output it as 1.0 instead.
CONSTRAINTS
4 <= N <= 50000
1 <= Q <= 50000
-20,000,000 <= x,y <= 20,000,000
0 <= a < b-1
b < N
SAMPLE INPUT
4 2
0 0
0 1
1 2
1 0
1 3
0 2
SAMPLE OUTPUT
0.5
0.5
EXPLANATION
The polygon is given by the points (0,0) (0,1) (1,2) (1,0).
In
the first query, we join the points (0,1) and (1,0) which leads to the 2
areas given by (0,0) (0,1) (1,0) and (0,1) (1,2) (1,0). The first
triangle has an area of 0.5 and the second triangle has an area of 1.
The minimum of these 2 is 0.5.
In the second query, we join the
points (0,0) and (1,2) which leads to the 2 areas given by (0,0) (0,1)
(1,2) and (0,0) (1,2) (1,0). The first triangle has an area of 0.5 and
the second triangle has an area of 1. The minimum of these 2 is 0.5.
题意 :求被两点分割的凸包面积的较小值 题意已经给出顺时针啦
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std; #define N 50005 struct Point
{
double x, y;
void read()
{
scanf("%lf%lf",&x,&y);
} } p[N]; double area(Point p0, Point p1, Point p2)
{
return fabs((p1.x-p0.x)*(p2.y-p0.y)*1.0-(p1.y-p0.y)*(p2.x-p0.x)*1.0)/2.0;
} int main()
{
double pol[N], res;
int n, q, a, b;
scanf("%d %d",&n, &q);
for(int i = ; i < n; i++)
{
p[i].read();
pol[i] = ;
} for(int i = ; i < n; i++)
pol[i] = pol[i-] + area(p[],p[i-],p[i]);
//for(int i=1;i<n;i++)
//cout<<pol[i]<<"~~~~~~~~~~~"<<endl; // printf("%.1lf\n", pol[n-1]); for(int i = ; i < q; i++)
{
scanf("%d %d",&a, &b);
//cout<<area(p[0],p[a],p[b])<<"~~~~~~~~~~"<<endl;
if(a == )
{
res = min(pol[b],pol[n-] - pol[b]);
}
else
{
res = pol[b] - pol[a] - area(p[], p[a], p[b]);
res = min(res, pol[n-] - res);
}
printf("%.1lf\n",res);
} return ;
}
A - Playground的更多相关文章
- 窥探Swift编程之在Playground上尽情的玩耍
自从苹果公司发布Swift的时候,Xcode上又多了一样新的东西---"Playground".Playground就像操场一样,可以供我们在代码的世界里尽情的玩耍,在本篇博客中就 ...
- 自制工具:迅速打开一个Node 环境的Playground
需求 经常有这种情况,写代码的时候需要实验种想法,亟需一种playground 环境来玩耍.如果是前端的话可以打开chrome 的控制台,但是如果是Node 的话就比较麻烦了.我要打开我的存放试验代码 ...
- Particle Playground 3.03 - 粒子特效王者
<ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op ...
- Swift开发第三篇——Playground
本篇分为两部分: 一.Playground的延时运行 二.Playground的可视化 一.Playground的延时运行 Playground 就是提供一个可以即时编译的类似 REPL 的环境,他为 ...
- TensorFlow Playground
A Neural Network Playground Understanding neural networks with TensorFlow Playground 机器之心翻译
- swift开发:试玩 Apple 站点的 playground
https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_ ...
- 使用Playground编写第一个Swift程序
从控制台输出“HelloWorld”是我学习C语言的第一步,也是我人生中非常重要的一步.多年后的今天,我仍希望以HelloWorld作为第一步,与大家共同开启一个神奇.瑰丽的世界——Swift编程. ...
- 0、IOS8:Xcode6 playground
一.Playground介绍 Playground是Xcode6中自带的Swift代码开发环境.俗话说“功欲善其事,必先利其器”.以前在Xcode5中编写脚本代码,例如编写JS,其编写过程很痛苦,Xc ...
- Swift 提示 error running playground...
创建playground之后,我们将得到一个错误提示,Error running playground: Failed to prepare for communication with playgr ...
- Swift开发学习(两):Playground
Swift开发学习:Playground 大约 对于软件用户.游戏玩家,我一直提倡用户体验.也是用户,是各种开发工具的使用者.也会喜欢用户体验做得好的工具软件.这次苹果想开发人员所想,提供了一个能够玩 ...
随机推荐
- Vim 基本配置
1.关闭vi的一致性模式 set nocompatible 2.配置backspace的工作方式 set backspace=indent,eol,start 3.显示行号 set number 4. ...
- MySQL 快速复数据库的方法
为了方便快速复制一个数据库,可以用以下命令将db1数据库的数据以及表结构复制到newdb数据库 创建新的数据库 #mysql -u root -p123456 mysql>CREATE DATA ...
- 什么是DevOps?DevOps简明教程
我希望每个测试人员经过..功能测试-接口测试-安全测试-自动化测试-性能测试的洗礼后 都可以进入DevOps阶段.具体什么以及为什么 我稍后会给你大家讲解...
- 重新设置Linux的IP地址(该操作会永久更改ip地址)
1.查看你当前的IP地址 2.进入配置文件进行更改IP地址 3.上图我使用的是ifcfg-eth1 ,然后进行更改这个文件 4.点击“insert”进行编辑改文档,吧对应的IP改成你想要的地址 更改完 ...
- activiti如何获取当前节点以及下一步路径或节点(转)
ACTIVITI相对于JBPM来说,比较年轻,用的人少,中文方面的资料更少,我根据网上到处找得资料以及看官方文档总结出来了代码,非常不容易啊.废话不多说,直接上代码吧: 首先是根据流程ID获取当前任务 ...
- 三大框架中各种xml的存放位置
web.xml中classpath:和classpath*: 有什么区别? classpath:只会到你的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar ...
- C语言基础第五次作业
题目7-2 统计一行文本的单词个数 1.实验代码 #include <stdio.h> int main() { char a; ,countword=; ){ scanf("% ...
- JNI,RegisterNative参数解析
Register native method - 数据类型和method descriptor 使用JNI时,为了使得虚拟机可以找到在C/C++ code中定义的native方法,有两种机制可以用,一 ...
- static关键字的功能
转载:https://blog.csdn.net/guotianqing/article/details/79828100 C语言&C++ 1.局部变量 如果在一个函数内部定义了一个静态变量, ...
- 使用PostSharp在.NET平台上实现AOP(转)
出处:https://www.cnblogs.com/leoo2sk/archive/2010/11/30/aop-postsharp.html 摘要 本文首先介绍AOP(面向方面编程)的相关概念及理 ...