当前位置:网站首页>【luogu P8031】Kućice(计算几何)
【luogu P8031】Kućice(计算几何)
2022-07-30 20:09:00 【SSL_TJH】
Kućice
题目链接:luogu P8031
题目大意
二维平面上有一些点,保证不存在重合的点和散点共线。
求每一个点集的凸包包含的点数的和。
思路
考虑如果每一个凸包都包含了每一个点,那答案是多少: n 2 n n2^{n} n2n
考虑减去不合法的,考虑是怎样的一种情况。
考虑枚举一个点,考虑它不在哪些点集中
不难想象如果你如果弄一个它跟另一个点的线(就是钦定这个点一定要在点集中),那你剩下可以选的点一定就只能在这个线划分成的半平面中的一侧。
那不难想到就是双指针,把其他的点按极角排序,然后用双指针维护固定的一面有多少个。
然后统计一种统计一面,因为另一边到时也会计算到。
然后你再看看如果这一面有 x x x 个点(假设包括上了你那条线上的另一个点),给多少的贡献,那就是 2 x 2^x 2x(因为你只看你一开始枚举的点是否贡献)
然后弄就好了。
代码
#include<cmath>
#include<cstdio>
#include<algorithm>
#define mo 1000000007
#define ll long long
using namespace std;
const int N = 1005;
struct node {
int x, y;
double k;
}a[N], b[N];
node operator +(node x, node y) {
return (node){
x.x + y.x, x.y + y.y, 0.0};}
node operator -(node x, node y) {
return (node){
x.x - y.x, x.y - y.y, 0.0};}
ll operator *(node x, node y) {
return 1ll * x.x * y.y - 1ll * x.y * y.x;}
int n;
ll jc[N], inv[N], invs[N], two[N], ans;
ll C(int n, int m) {
if (m < 0 || m > n) return 0;
return jc[n] * invs[m] % mo * invs[n - m] % mo;
}
ll ksm(ll x, int y) {
ll re = 1;
while (y) {
if (y & 1) re = re * x % mo;
x = x * x % mo; y >>= 1;
}
return re;
}
void Init() {
jc[0] = 1; for (int i = 1; i < N; i++) jc[i] = jc[i - 1] * i % mo;
inv[0] = inv[1] = 1; for (int i = 2; i < N; i++) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
invs[0] = 1; for (int i = 1; i < N; i++) invs[i] = invs[i - 1] * inv[i] % mo;
two[0] = 1; for (int i = 1; i < N; i++) two[i] = two[i - 1] * 2 % mo;
}
bool cmp(node x, node y) {
return x.k < y.k;}
int main() {
freopen("booth.in", "r", stdin);
freopen("booth.out", "w", stdout);
Init();
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &a[i].x, &a[i].y);
}
ans = (two[n] - 1 + mo) % mo * n % mo;
for (int i = 0; i < n; i++) {
int m = 0;
for (int j = 0; j < n; j++) if (j != i)
b[m++] = a[j] - a[i], b[m - 1].k = atan2(b[m - 1].y, b[m - 1].x);
sort(b, b + m, cmp);
int now = 0;
for (int j = 0; j < m; j++) {
while (j != (now + 1) % m && b[j] * b[(now + 1) % m] > 0) now = (now + 1) % m;
(ans += mo - two[(now - j + m) % m] % mo) %= mo;
}
}
printf("%lld", ans);
return 0;
}
边栏推荐
- 树形结构:二叉树的递归非递归遍历、BST
- [PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
- Redisson 的分布式锁找不到?
- 明解C语言第五章习题
- 360杜跃进:太空安全风险加剧,需打造一体化防御体系
- 推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
- 都在说软件测试没前途,饱和了?为何每年还会增加40万测试员?
- Interviewer Ali: Describe to me the phenomenon of cache breakdown, and talk about your solution?
- Multi-threaded mutex application RAII mechanism
- mysql慢查询优化
猜你喜欢

对int变量赋值的操作是原子的吗?

ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法

都在说软件测试没前途,饱和了?为何每年还会增加40万测试员?

Linux download and install mysql5.7 version tutorial the most complete and detailed explanation

Cesium loads offline maps and offline terrain

YOLO V3详解

ECCV2022 | 对比视觉Transformer的在线持续学习

我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你

如何优化OpenSumi终端性能?

PPT如何开启演讲者模式?PPT开启演讲者模式的方法
随机推荐
Zabbix部署与练习
Linux下载安装mysql5.7版本教程最全详解
PHP低代码开发引擎—表单设计
使用MULTISET来比较数据集的实例介绍
对int变量赋值的操作是原子的吗?
M3SDA:用于多源域自适应的矩匹配
vlookup函数匹配不出来只显示公式的解决方法
明解C语言第五章习题
DCM 中间件家族迎来新成员
湖仓一体电商项目(四):项目数据种类与采集
PostgreSQL 14.4如何安装使用
我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你
Cesium加载离线地图和离线地形
WPS表格怎么自动1234排下去?wps表格怎么自动生成序号?
Centos7 install mysql8
[Ask] SQL statement to calculate the sum of column 2 by deduplicating column 1?
银行数据资产转换能力弱?思迈特软件助力解决银行困境
树形结构:二叉树的递归非递归遍历、BST
Is the iPhone really thirteen incense?The two generations of products are completely compared, perhaps the previous generation is more worth buying
The technology is very powerful, do you still need to "manage up"?