计数每一个点被被其他点组成的四边形完全包含的四边形的个数,给出的点没有三点共线的情况

官方题解如下,说的很清楚,也很有技巧

代码也是直接参考官方的题解来的

#include<bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fore(i, s, t) for (int i = s; i < (int)t; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x) cout<<it<<endl;
#define pi pair<int,int> using namespace std; char inline nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
} template <typename T>
bool rd(T& v){
static char ch;
while(ch!=EOF&&!isdigit(ch)) ch=nc();
if(ch==EOF) return false;
for(v=0;isdigit(ch);ch=nc())
v=v*10+ch-'0';
return true;
} template <typename T>
void o(T p){
static int stk[70],tp;
if(p==0) {
putchar('0');return ;
}
if(p<0) {
p=-p;putchar('-');
}
while(p) stk[++tp]=p%10,p/=10;
while(tp) putchar(stk[tp--]+'0');
} typedef long long ll; const int maxn=3e3+5;
const int maxm=4e5+5;
const int inf=1e9; int n; pi a[maxn]; ll C(ll n,ll m){
if(m>n) return 0;
if(n<0) return 0;
if(m>n-m) m=n-m;
ll ans=1;
for(int i=1;i<=m;i++)
ans*=n,ans/=i,n--;
return ans;
} ll cross(pi a,pi b){
return 1ll*a.fi*b.se-1ll*b.fi*a.se;
} int main(){
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i].fi>>a[i].se;
ll tot=0;
for(int i=0;i<n;i++){
vector<pi> v;
for(int j=0;j<n;j++)
if(i!=j) v.push_back({a[j].fi-a[i].fi,a[j].se-a[i].se});
sort(all(v),[&](pi x,pi y){
bool b1=x<pi(0,0);
bool b2=y<pi(0,0);
if(b1!=b2) return b1<b2;
return cross(x,y)>0;
});
int j=0;
for(int i=0;i<v.size();i++){
while(j<i+v.size()&&cross(v[i],v[j%v.size()])>=0) j++;
tot+=C(j-i-1,3);
}
}
cout<<C(n,5)*5-tot<<endl;
}
 

  

codeforces 1284E的更多相关文章

  1. codeforces 1284E. New Year and Castle Construction(极角排序+扫描枚举)

    链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. Golang import具体使用

    使用gopath的时候,一般引用是从src下一层开始,比如src/github.com/…,引用github.com…,我的工程src/xxx.com/go-qb/…,引用xxx.com/go-qb/ ...

  2. 5年从DBA到运维架构总监 — 做对了什么

    本文来自宝宝树运维总监刘秋岐的分享.随着MySQL的不断成熟,逐渐被用于更多大规模的网站和应用了,比如说当前最火的Facebook.淘宝.阿里.兰亭集势.宝宝树这样的大型的网站都在使用MySQL数据库 ...

  3. NR / 5G - Downlink Carrier Waveform

  4. PyObject and PyTypeObject - Python 中的 '对象' 们

    1 PyObject, PyTypeObject - Python 中的 '对象' 们 '一切皆对象' - 这是 Python 的学习和使用者们最最常听到一句, 可谓 博大精深 - '勃大精深'. ' ...

  5. 苹果系统iOS、macOS应用管理机制

    iOS.macOS系统应用管理机制 苹果系统包括:iOS.macOS.watchOS.tvOS.应用软件的生命周期为:开发.上线.安装.使用.卸载.这篇文档将从应用生命周期的各个环节介绍苹果系统对应用 ...

  6. 04-Spring01-IOC

    今日知识 1. Spring IOC控制反转(Inverse of control) 2. Spring DI依赖注入(Dependency Injection ) Spring 1. 概念:简单来说 ...

  7. 数据算法 --hadoop/spark数据处理技巧 --(17.小文件问题 18.MapReuce的大容量缓存)

    十七.小文件问题 十八.MR的大容量缓存 在MR中使用和读取大容量缓存,(也就是说,可能包括数十亿键值对,而无法放在一个商用服务器的内存中).本次提出的算法通用,可以在任何MR范式中使用.(eg:MR ...

  8. 使用FIO工具测试块存储性能

    Linux实例和Windows实例都推荐使用FIO工具测试块存储性能.   说明 您也可以使用其他工具测试块存储性能,但不同工具测试出来的硬盘基准性能会有差异,如dd.sysbench.iometer ...

  9. [20200211]使用DBMS_SHARED_POOL.MARKHOT与sql_id的计算.txt

    [20200211]使用DBMS_SHARED_POOL.MARKHOT与sql_id的计算.txt --//以前写的,使用DBMS_SHARED_POOL.MARKHOT标记热的sql_id,这样相 ...

  10. redis 5.0.7 源码阅读——整数集合intset

    redis中整数集合intset相关的文件为:intset.h与intset.c intset的所有操作与操作一个排序整形数组 int a[N]类似,只是根据类型做了内存上的优化. 一.数据结构 ty ...