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 大约 对于软件用户.游戏玩家,我一直提倡用户体验.也是用户,是各种开发工具的使用者.也会喜欢用户体验做得好的工具软件.这次苹果想开发人员所想,提供了一个能够玩 ...
随机推荐
- MAC/Xcode简单操作命令
快捷键: command(windows) + c: 复制 command + V : 粘贴 command + x: 剪切(只在当前应用程序内有效) 在mac系统下表示剪切功能: 先command ...
- Luogu1070-道路游戏-动态规划
Solution 用对角线的前缀和快速进行转移,复杂度$O(N^3)$, 洛谷神机太快了$N^3$都能过 然而正解是单调队列优化, 能优化到$O(N^2)$,然而我弱得什么都不会 Code #incl ...
- wait()和sleep()的区别
wait()是Object类的方法,当一个线程执行到wait()方法时,该线程就进入到一个和该线程相关的等待池中,同时释放了对象锁(暂时失去对象锁,wait(long timeout)超时时间到后还需 ...
- Python之路(第二十篇) subprocess模块
一.subprocess模块 subprocess英文意思:子进程 那什么是进程呢? (一)关于进程的相关理论基础知识 进程是对正在运行程序的一个抽象,进程的概念起源于操作系统,是操作系统最核心的概念 ...
- 全面了解HTTP请求方法说明
超文本传输协议(HTTP, HyperText Transfer Protocol)是一种无状态的协议,它位于OSI七层模型的传输层.HTTP客户端会根据需要构建合适的HTTP请求方法,而HTTP服务 ...
- Sophus链接错误
错误指示如下: CMakeFiles/run_vo.dir/run_vo.cpp.o: In function `main': run_vo.cpp:(.text.startup+0x1086): u ...
- Windows-universal-samples学习笔记系列二:Controls, layout, and text
Controls, layout, and text AutoSuggestBox migration Clipboard Commanding Context menu Context menu ( ...
- Android Makefile中是 如何识别 TARGET_PRODUCT 的
http://blog.csdn.net/stevenliyong/article/details/5285334 今天有时间小看一下Android 的Makefile, 终于稍有明白Android ...
- 使用thymeleaf一旦没有闭合标签就会报错怎么解决
问题:input标签未关闭报bug,代码稍有不慎就出小问题 使用springboot的thymeleaf模板时默认会对HTML进行严格的检查,导致当你的标签没有闭合时就会通不过,例如: //要想通过, ...
- 2018.10.25 uestc上天的卿学姐(计数dp)
传送门 看了DZYODZYODZYO的题解之后发现自己又sbsbsb了啊. 直接dpdpdp是O(2d)O(2^d)O(2d)更新,O(1)O(1)O(1)查询或者O(1)O(1)O(1)更新,O(2 ...