题意:给一个凸多边形,求任选若干点形成的多边形的面积和。

思路:

  • 按一定方向(顺时针或逆时针)对多边形的顶点进行编号,则多边形的面积计算公式为:f1 x f2 + fx f3 + ... fn-1 x f+ fn x f1,f表示从参考点到i的向量。
  • 考虑fx fj 在答案中出现的次数,则答案可以写成:fi x fj * 2n-(j-i+1) (i<j) 或 fx f* 2i-j-1(i>j),直接枚举i和j是O(n2)的,显然不行。
  • 由叉积的性质:∑(fi x P) = (∑fi) x P,可以预处理出fi*2i-1的前缀和以及fi/2i+1的前缀和,复杂度O(n),从而只需枚举一维,另一维的和O(1)得到,总复杂度O(n)。

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>
using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii; namespace Debug {
void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<" ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
}
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
/* -------------------------------------------------------------------------------- */ const int maxn = 1e5 + ;
const int mod = 1e9 + ; struct Point {
ll x, y;
void read() {
int x, y;
scanf("%d%d", &x, &y);
this->x = x;
this->y = y;
}
Point(int x, int y) {
this->x = x;
this->y = y;
}
Point() {}
Point operator + (const Point &that) const {
return Point((x + that.x) % mod, (y + that.y) % mod);
}
Point operator * (const int &m) const {
return Point(x * m % mod, y * m % mod);
}
};
Point p[maxn], g[maxn], h[maxn];
int two[maxn], twoinv[maxn]; int cross(Point &a, Point &b) {
return (a.x * b.y % mod - a.y * b.x % mod + mod) % mod;
} int powermod(int a, int n, int mod) {
ll ans = , buf = a;
while (n) {
if (n & ) ans = (ans * buf) % mod;
buf = buf * buf % mod;
n >>= ;
}
return ans;
} void init() {
ll inv = powermod(, mod - , mod);
two[] = twoinv[] = ;
for (int i = ; i < maxn; i ++) {
two[i] = (two[i - ] + two[i - ]) % mod;
twoinv[i] = twoinv[i - ] * inv % mod;
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, n;
cin >> T;
init();
while (T --) {
cin >> n;
for (int i = ; i <= n; i ++) {
p[i].read();
g[i] = g[i - ] + p[i] * two[i - ];
h[i] = h[i - ] + p[i] * twoinv[i + ];
}
int ans = ;
for (int i = ; i <= n; i ++) {
Point buf = p[i] * two[n - i];
ans = (ans + cross(g[i - ], buf)) % mod;
}
for (int i = ; i <= n; i ++) {
Point buf = p[i] * two[i];
ans = (ans + cross(buf, h[i - ])) % mod;
}
cout << ans << endl;
}
}

[hdu5448 Marisa’s Cake]多边形面积,公式化简的更多相关文章

  1. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

  2. 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

    题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...

  3. 三角剖分求多边形面积的交 HDU3060

    //三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...

  4. CF 107E 多边形面积并

    107E Darts 题目:给出n个矩形,问落在n个矩形交的部分的概率 分析:裸的多边形面积并. 代码略..

  5. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  6. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...

  7. [ECNU 1624] 求交集多边形面积

    求交集多边形面积 Time Limit:1000MS Memory Limit:30000KB Total Submit:98 Accepted:42 Description 在平面上有两给定的凸多边 ...

  8. Area - POJ 1654(求多边形面积)

    题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...

  9. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

随机推荐

  1. Laravel 5.8 RCE 分析

    原帖地址 : https://xz.aliyun.com/t/6059 Laravel 代码审计 环境搭建 composer create-project --prefer-dist laravel/ ...

  2. vue结合百度地图Api实现周边配置查询及根据筛选结果显示对应坐标详情

    在我们平常写房地产相关项目的时候经常会用到百度地图,因为这一块客户会考虑到房源周围的配套或者地铁线路所以在这类项目中就不可以避免的会用到百度地图,当然这只是其中一种,其他地图工具也可以,因为我这个项目 ...

  3. python 基础篇 自定义函数

    多态 我们可以看到,Python 不用考虑输入的数据类型,而是将其交给具体的代码去判断执行,同样的一个函数(比如这边的相加函数 my_sum()),可以同时应用在整型.列表.字符串等等的操作中. 在编 ...

  4. 大部分人都不知道的8个python神操作

    01 print 打印带有颜色的信息 大家知道 Python 中的信息打印函数 Print,一般我们会使用它打印一些东西,作为一个简单调试. 但是你知道么,这个 Print 打印出来的字体颜色是可以设 ...

  5. 2019-2020-1 20199308《Linux内核原理与分析》第一周作业

    Linux 基础入门(新版)学习笔记 实验二 基本概念及操作 重要快捷键 Tab 补全命令 Ctrl+c 强行终止当前命令 历史命令 方向上键↑,恢复之前输入过的命令 通配符 在命令行中获取帮助 某个 ...

  6. 2019-2020-1 20199329《Linux内核原理与分析》第三周作业

    <Linux内核原理与分析>第三周作业 一.上周问题总结: 第二周头脑风暴完成较慢 虚拟机libc配置错误 书本知识使用不够熟练 二.本周学习内容: 1.实验楼环境虚拟一个x86的CPU硬 ...

  7. Add text to 'Ready Page' in Inno Setup

    https://stackoverflow.com/questions/1218411/add-text-to-ready-page-in-inno-setup

  8. webpack插件解析:HtmlWebpackPlugin是干什么的以及如何使用它

    HtmlWebpackPlugin是一个出现频率比较高的webpack插件,本文对其作用和配置作一番比较详细的分析(本文的配置均在webpack.config.js中进行). 为何使用它 简单来说,H ...

  9. Eclipse Mac OS 安装中文简体语言包

    打开Eclipse软件,在导航Eclipse下拉菜单中点开 About Eclipse 查看版本 我的是 Eclipse IDE for Enterprise Java Developers. Ver ...

  10. 使用react脚手架create-react-app创建react应用

    Create React App是一种官方支持的创建单页React应用程序的方法.它提供了一个没有配置的现代构建设置. 一.全局安装脚手架: npm install -g create-react-a ...