题目链接

https://codeforces.com/contest/1284/problem/E

题解

我们计算选出 \(3\) 个点构成三角形覆盖的点数之和,这个值乘以 \(\frac{(n-4)}{2}\) 就是答案。这是因为对于任意一个(凸或凹,根据题意凹的多种凹法只算一次)四边形,从 \(4\) 个顶点中选出 \(3\) 个构成三角形的 \(4\) 种方案中每个被四边形覆盖的点恰好被 \(2\) 种方案覆盖。
然后就比较套路了,补集转化,枚举一个点求有多少个三角形不包含它,然后其余的点以它为中心按极角排序,枚举最顺时针的那个,算从它的一侧选出两个点的方案数。
不过似乎没发现三角形那个性质大力扫描线也能做,好题->垃圾题?
时间复杂度 \(O(n^2\log n)\).

代码


#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
#define y1 Lorem_ipsum_dolor
using namespace std;inline int read()
{int x = 0,f = 1; char ch = getchar();for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}return x*f;
}const int mxN = 2500;
struct Point
{llong x,y;Point() {}Point(llong _x,llong _y):x(_x),y(_y) {}int quadrant() {return x>0?(y<0):(y<=0);}
} a[mxN+3],b[(mxN<<1)+3];
typedef Point Vector;
Point operator +(Point x,Point y) {return Point(x.x+y.x,x.y+y.y);}
Point operator -(Point x,Point y) {return Point(x.x-y.x,x.y-y.y);}
llong Cross(Vector x,Vector y) {return x.x*y.y-x.y*y.x;}int n;bool cmp_ang(Point x,Point y) {return x.quadrant()^y.quadrant()?x.quadrant()<y.quadrant():Cross(x,y)>0;}int main()
{scanf("%d",&n);for(int i=1; i<=n; i++) scanf("%I64d%I64d",&a[i].x,&a[i].y);llong ans = 0ll;for(int i=1; i<=n; i++){for(int j=1; j<=n; j++) b[j] = a[j]-a[i]; swap(b[i],b[1]);sort(b+2,b+n+1,cmp_ang);
//      printf("i=%d\n",i);
//      for(int j=2; j<=n; j++) printf("(%lld,%lld)\n",b[j].x,b[j].y);for(int j=2; j<=n; j++) b[n-1+j] = b[j];int j,k; llong cur = 0ll;for(j=2,k=3; j<=n; j++){while(k<=j||Cross(b[j],b[k])>0) {k++;}int cnt = j+n-1-k;
//          printf("j=%d k=%d cnt=%d\n",j,k,cnt);cur += 1ll*cnt*(cnt-1ll)/2ll;}ans += cur;}ans = (1ll*n*(n-1ll)*(n-2ll)*(n-3ll)/6ll-ans)*(n-4ll)/2ll;printf("%I64d\n",ans);return 0;
}

Codeforces 1284E New Year and Castle Building (计算几何)相关推荐

  1. 【CodeForces - 340B 】Maximal Area Quadrilateral (计算几何,枚举,有坑)

    题干: Iahub has drawn a set of n points in the cartesian plane which he calls "special points&quo ...

  2. D - Sand Fortress CodeForces - 985D

    D - Sand Fortress CodeForces - 985D number of spots you can occupy so that all the aforementioned co ...

  3. 【CodeForces - 985D】Sand Fortress (二分,贪心,思维构造,技巧,有坑)

    题干: You are going to the beach with the idea to build the greatest sand castle ever in your head! Th ...

  4. codeforces+contest+985D. Sand Fortress+思维

    二分枚举长度 去算这一个点左边有多少个 D. Sand Fortress time limit per test 2 seconds memory limit per test 256 megabyt ...

  5. Codeforces 1025F Disjoint Triangles (计算几何)

    题目链接 https://codeforces.com/contest/1025/problem/F 题解 一道挺有意思的计算几何题 qwq 关键在于注意到任何一对不相交的三角形之间,一定有 \(2\ ...

  6. Codeforces Round #587 C. White Sheet(思维+计算几何)

    传送门 •题意 先给一个白矩阵,再两个黑矩阵 如果两个黑矩阵能把白矩阵包含,则输出NO 否则输出YES •思路 计算几何题还是思维题呢? 想起了上初中高中做几何求面积的题 这个就类似于那样 包含的话分 ...

  7. 【CodeForces - 1020A】New Building for SIS(模拟)

    题干: You are looking at the floor plan of the Summer Informatics School's new building. You were task ...

  8. Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何

    主题链接:点击打开链接 必须指出的是,反射镜和2个人共线是不是障碍,但根据该壁其他情况 #include<cstdio> #include<iostream> #include ...

  9. hdu 4667 Building Fence 计算几何模板

    1 //大白p263 2 #include <cmath> 3 #include <cstdio> 4 #include <cstring> 5 #include ...

最新文章

  1. 雨林木风爱好者GHOSTXP装机版_NTFS_SP3_2010_03
  2. POJ 3040 Allowance【贪心】
  3. 在企业内部使用openssl创建私有CA
  4. [CDA数据分析师学习之路] 【CDA就业班独家发布】学习之路
  5. 安装后添加没有class library_《没有秘密的你》:戚薇曝光手机号,粉丝急忙添加后却甜哭了?...
  6. Android第三夜
  7. java面向对象第一课,定义类,模拟人的行为:吃饭工作休息
  8. easyexcel导入简单封装
  9. android command line tools 下载,Mac 安装 Android commandlinetools 各种报错的问题
  10. 20211109:DC综合的一些简单概念理解记录
  11. 【记忆化递归+DP】LeetCode 139. Word Break
  12. Ubuntu18.04连蓝牙键盘后,搜狗输入法导致输入卡顿问题
  13. hadoop常见问题汇总
  14. 用Python实现BP神经网络(附代码)
  15. cacti监控mysql
  16. 【图像分割】基于matlab人工鱼群算法图像分割【含Matlab源码 1488期】
  17. 前端工程化——Livereload和HMR、本地开发服务器
  18. 组装计算机的主要配置,自己组装电脑的基本配置跟一些注意事项
  19. Raft 论文精读笔记|In Search of an Understandable Consensus Alg orithm (Extended Version)
  20. 基于局部自适应色差阈值的彩色图像边缘检测_爱学术

热门文章

  1. Feed43自定义 RSS 订阅源
  2. Android常用的开源框架
  3. 技术贴]强大的DELPHI RTTI–兼谈需要了解多种开发语言
  4. BUUCTF-Reverse:新年快乐 + 加壳与脱壳
  5. 青蛙跳台阶问题(思路与蜂窝问题一致)
  6. setup.s 分析—— Linux-0.11 学习笔记(二)
  7. TCP的三次握手与四次挥手图文
  8. Nginx反向代理负载均衡时,验证码不正确
  9. 问:一行Python代码到底能干多少事情?(三)
  10. springboot学习笔记(九)