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 = 0; i < n; i++)
    {
        p[i].read();
        pol[i] = 0;
    }

    for(int i = 2; i < n; i++)
        pol[i] = pol[i-1] + area(p[0],p[i-1],p[i]);
    //for(int i=1;i<n;i++)
    //cout<<pol[i]<<"~~~~~~~~~~~"<<endl;

    // printf("%.1lf\n", pol[n-1]);

    for(int i = 0; i < q; i++)
    {
        scanf("%d %d",&a, &b);
        //cout<<area(p[0],p[a],p[b])<<"~~~~~~~~~~"<<endl;
        if(a == 0)
        {
            res = min(pol[b],pol[n-1] - pol[b]);
        }
        else
        {
            res = pol[b] - pol[a] - area(p[0], p[a], p[b]);
            res = min(res, pol[n-1] - res);
        }
        printf("%.1lf\n",res);
    }

    return 0;
}

A - Playground

时间: 2024-08-11 03:37:41

A - Playground的相关文章

Playground 你不知道的小技巧, CoreData 的使用

Playground 的出现无疑是大大的提高了开发效率,可以节省大量的编译时间. 这里介绍在 Playground 中使用 CoreData 的小技巧. 我们新建一个工程 iOS 项目工程. 点击 File -> New -> File , 在工程中新建文件 Data Model 文件  在 model 中添加一个 Entitle,如下图  编译工程后,在 Product 选择生成的 .app 文件,找到该目录,如下图  查看包中的文件,如图  可以看到一个 Mode.momd 文件, 如图 

PLAYGROUND 延时运行

PLAYGROUND 延时运行 由 王巍 (@ONEVCAT) 发布于 2015/09/16 从 WWDC 14 的 Keynote 上 Chris 的演示就能看出 Playground 异常强大,但是从本质来说 Playground 的想法其实非常简单,就是提供一个可以即时编辑的类似 REPL 的环境. Playground 为我们提供了一个顺序执行的环境,在每次更改其中代码后整个文件会被重新编译,并清空原来的状态并运行.这个行为与测试时的单个测试用例有一些相似,因此有些时候在测试时我们会遇到

使用Playground编写第一个Swift程序

从控制台输出"HelloWorld"是我学习C语言的第一步,也是我人生中非常重要的一步.多年后的今天,我仍希望以HelloWorld作为第一步,与大家共同开启一个神奇.瑰丽的世界--Swift编程. 本章以HelloWorld作为切入点,向大家系统介绍如何使用Xcode的Playground编写和运行Swift程序代码. 编写和运行Swift程序有多种方式,我们可以通过在Xcode中创建一个iOS或Mac OS X工程来实现,也可以通过使用Xcode6提供的Playground来实现.

PLAYGROUND 可视化

PLAYGROUND 可视化 由 王巍 (@ONEVCAT) 发布于 2015/09/23 在程序界,很多小伙伴都会对研究排序算法情有独钟,并且试图将排序执行的过程可视化,以便让大家更清晰直观地了解算法步骤.有人把可视化排序做得很正统明了,也有人把它做到了艺术层次. 想在 Cocoa 中做一个可视化的排序算法演示可不是一件容易的事情,很可能你会需要一套绘制图形的框架,并且考虑如何在屏幕上呈现每一步的过程.但是在 Playground 中事情就变得简单多了:我们可以使用 XCPlayground 

2.Swift的playground与OC语法对比

1.playground 1.1 简介 在2014年的WWDC大会上,苹果公司正式公布了Swift——一款面向苹果移动设备软件开发工作的全新编程语言.为了配合新语言的诞生,Xcode 6新增了一项名为Playgrounds的功能——这其实是一套交互工作区,开发人员可以在此编写Swift代码并在无需将其运行在设备或者模拟器中的前 提下获取实时运行效果反馈.这对于Xcode来说无疑是一种很好的补充,现在各位可以在将自己的代码成果正式添加到主代码库内之前,以实验性方式快速便捷 地掌握地实时运行效果 1

swift笔记二 playground

New a playgroud放在桌面. Name: foo Platform: OS X 在桌面会生成一个叫foo.playground的文件, View > Assistant Editor > show assistant editor(on bottom)可以上你方便的看到出错信息. 双击foo.playground可以直接打开,,右击show package contents可以将playground中对应的***.swift文件拷贝出来..

[Swift] 使用Playground

使用Playground 1. 新建Playground 2. 写最简单的代码

Playground 快速原型制作(转)

由于使用 Cocoa 框架能够快速地创建一个可用的应用,这让许多开发者都喜欢上了 OS X 或 iOS 开发.如今即使是小团队也能设计和开发复杂的应用,这很大程度上要归功于这些平台所提供的工具和框架.Swift 的 Playground 不仅继承了快速开发的传统,并且有改变我们设计和编写 OS X 和 iOS 应用方式的潜力. 向那些还不熟悉这个概念的读者解释一下,Swift 的 playground 就像是一个可交互的文档,在其中你可以输入 Swift 代码让它们立即编译执行.操作结果随着执行

【iOS】Swift中Playground,常量、变量、字符串等小结

一.代码及书写的几点变化(相比于OC) 1. 更像Java,Javascript或Python的格式了 2. 结尾的分号可写可不写了(同一行的多条语句中间必须加分号) 3. 不需要写main函数了,直接是从上往下执行 4. 文件后缀变.swift了,不再是.h与.m两个文件了 ...... 二.Playground Playground顾名思义,Play是玩的意思,ground是地方的意思.拿来玩.写demo或者测试很nice.在WWDC上演示了Playground实时显示,并演示了一个简单的小

[GraphQL] Deploy a GraphQL dev playground with graphql-up

In this lesson we'll use a simple GraphQL IDL schema to deploy and explore a fully functional GraphQL service in minutes with graphql-up. Install: npm i -g graphql-up -g Create schema: type Person { id: ID!, name: String!, tasks: [Task!]! @relation(n