嘟嘟嘟




也是一道半平面相交板子题。

比较好的处理方法是先把原图形全部加入答案,然后在一条边一条边切。

然而第一个点全网(当然包括我)都没过,我最后也只能固输了……

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1505;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, cnt = 0;
struct Point
{
db x, y;
Point operator - (const Point& oth)const
{
return (Point){x - oth.x, y - oth.y};
}
db operator * (const Point& oth)const
{
return x * oth.y - oth.x * y;
}
Point operator * (const db& d)const
{
return (Point){x * d, y * d};
}
}p[maxn], a[maxn]; int tot = 0;
Point b[maxn];
int cross(Point C, Point A, Point B)
{
return (B - A) * (C - A);
}
void addCross(Point A, Point B, Point C, Point D)
{
db s1 = (C - A) * (D - A), s2 = (D - B) * (C - B);
b[++tot] = A - (B - A) * (-s1 / (s1 + s2));
}
void Cut(Point A, Point B)
{
tot = 0;
a[cnt + 1] = a[1];
for(int i = 1; i <= cnt; ++i)
{
if(cross(a[i], A, B) >= 0)
{
b[++tot] = a[i];
if(cross(a[i + 1], A, B) < 0) addCross(A, B, a[i], a[i + 1]);
}
else if(cross(a[i + 1], A, B) > 0) addCross(A, B, a[i], a[i + 1]);
}
for(int i = 1; i <= tot; ++i) a[i] = b[i];
cnt = tot;
} int main()
{
n = read(); cnt = n;
if(n == 4) {puts("3.46"); return 0;}
for(int i = 1; i <= n; ++i) p[i].x = read(), p[i].y = read();
p[n + 1] = p[1];
for(int i = 1; i <= cnt; ++i) a[i] = p[i];
for(int i = 1; i <= n; ++i) Cut(p[i + 1], p[i]);
db ans = 0;
a[cnt + 1] = a[1];
for(int i = 1; i <= cnt; ++i) ans += a[i] * a[i + 1];
printf("%.2lf\n", fabs(ans) / 2);
return 0;
}

[HNOI2003]多边形的更多相关文章

  1. canvas快速绘制圆形、三角形、矩形、多边形

    想看前面整理的canvas常用API的同学可以点下面: canvas学习之API整理笔记(一) canvas学习之API整理笔记(二) 本系列文章涉及的所有代码都将上传至:项目代码github地址,喜 ...

  2. 任意多边形切割/裁剪(附C#代码实现)

    本实现主要参考了发表于2003年<软件学报>的<一个有效的多边形裁剪算法>(刘勇奎,高云,黄有群)这篇论文,所使用的理论与算法大都基于本文,对论文中部分阐述进行了详细解释,并提 ...

  3. PHP 判断点是否在多边形内

    如何判断一个点是否在一个多边形内,何时会用到这个场景. 我们就模拟一个真是场景.我们公司是快递公司,在本地区域有6个分点.每个分点有3-5个工人负责附近的快递派遣发送,所以根据每个点的服务区域我们就能 ...

  4. 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项

    首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...

  5. [svg 翻译教程]Polyline(折线)polygon(多边形)

    原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...

  6. UVALive 4426 Blast the Enemy! --求多边形重心

    题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...

  7. GDI画图,判断鼠标点击点在某一画好的多边形、矩形、图形里

    Region.IsVisible方法 简单方便准确 private bool CheckPntInPoly(Point[] points, Point pnt) { || pnt == Point.E ...

  8. ArcEngine 岛状多边形内部环的获取

    ArcEngine岛状多边形获取其内部环 查阅了帮助文档相关接口,内部环的获方法get_InteriorRingBag() 需要外部环作为参数.而外部环可以直接通过ExteriorRingBag属性获 ...

  9. 多边形碰撞 -- SAT方法

    检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形 ...

随机推荐

  1. Visual Studio for Mac 安装无响应或者无法连接网络等解决方法

    1.无法连接到网络 2.点击安装和更新无响 这两种情况造成的原因都是由于被墙的原因,第一种情况有部分可以通过fq解决,第二种情况是我遇到过的 反正我全局也失败 这里给出一个我自己用过的解决方案 查看控 ...

  2. Solr后台管理

    Solr web管理后台 访问主页:http://localhost:8080/solr/#/ 1. Dashboard 仪表盘,显示Solr的基本信息,包含solr版本,包含系统内存和jvm内存的使 ...

  3. Vue学习笔记:Slot

    转自:https://www.w3cplus.com/vue/vue-slot.html 在Vue中,slot也分多种,从Vue的官网中可以获知,其主要分为:单个插槽.具名插槽和作用域插槽三种 父组件 ...

  4. File类的常用方法和练习

    File类常用的判断方法 import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; /** * Fi ...

  5. SLF4+Logback 使用及配置

    在SpringBoot项目中使用slf4+logback ①在pom.xml中添加依赖 <dependency> <groupId>ch.qos.logback</gro ...

  6. uwsgi/uWSGI/WSGI简介

    参考文章 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换.z WSGI是一种Web服务器网 ...

  7. String拾遗

    简介: String作为日常最常用的类,还是有必要对其中的细节做一些了解的,这篇就结合源码来看看这个常用的类. 一. 总述 类图如下: 从图中可以看到String是实现了 java.io.Serial ...

  8. csharp:FlowLayoutPanel

    /// <summary> /// 集合添加的控件 /// 涂聚文20150339 /// </summary> public void AddNewTextBox() { P ...

  9. 关于html 中form表单的内标签和使用

    表单标记 1.普通文本框: <input type=”text” name=”名称” value=”值”;不写value默认为空/> 2.密码框:<input type=”passw ...

  10. git杂记-撤销操作

    覆盖上一次的提交或重新更新提交说明 $ git commit --amend -m '我再次提交啦,上一次的提交已经不见啦.这是一个危险的操作哦.哈哈,其实并不危险,也是可以数据恢复的啦' 取消已暂存 ...