codeforces 1284E


计数每一个点被被其他点组成的四边形完全包含的四边形的个数,给出的点没有三点共线的情况
官方题解如下,说的很清楚,也很有技巧

代码也是直接参考官方的题解来的
#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的更多相关文章
- codeforces 1284E. New Year and Castle Construction(极角排序+扫描枚举)
链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 使用Redis需要注意的几点
Redis作为缓存中间件,被广泛应用在各类系统,用来提升系统性能和吞吐,下面总结几点开发人员在使用Redis时需要考虑的几个关键点: 一. key的设计 1. key命名规范:为了避免不必要的麻烦,我 ...
- java jdk1.8 32/64位 官方绿色版下载附安装教程
java jdk1.8 32/64位 官方绿色版下载附安装教程 地址:https://www.jb51.net/softs/691593.html
- 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第六节:反爬策略研究
之前的章节也略有提及反爬策略,本节,我们就来系统的对反爬.反反爬的种种,做一个了结. 从防盗链说起: 自从论坛兴起的时候,网上就有很多人会在论坛里发布一些很棒的文章,与当下流行的“点赞”“分享”一样, ...
- postman之设置token
在做接口测试的时候,很多业务的接口是有依赖性的,下一个接口需要上一个接口的token依赖,例如余额查询接口,需要先登录,才能查询余额.那么,这种接口如何使用postman进行测试呢?今天让我来给小伙伴 ...
- golang中使用Shutdown特性对http服务进行优雅退出使用总结
golang 程序启动一个 http 服务时,若服务被意外终止或中断,会让现有请求连接突然中断,未处理完成的任务也会出现不可预知的错误,这样即会造成服务硬终止:为了解决硬终止问题我们希望服务中断或退出 ...
- 渡一教育公开课重点笔记之css
主流浏览器及内核 浏览器 内核 IE trident Firefox Gecko Google chrome Webkit/blink(2014年上 ...
- JAVA System.exit(0) 和 System.exit(1) 的区别
System.exit(int state) 方法都是来结束当前运行的java虚拟机.所有System.exit(1).System.exit(0) 执行后都会退出程序. state为0时时正常退出, ...
- OSPFv3与OSPFv2协议的比较
From: http://blog.sina.com.cn/s/blog_61bd83dc0100la2u.html OSPFv3与OSPFv2协议的比较 OSPF是一种链路状态路由协议.它具有标 ...
- [MSSQL]xp_cmdshell 查看磁盘空间
EXEC xp_cmdshell 'wmic logicaldisk get freespace,caption | findstr C'; <class 'pyodbc.Row'> (' ...
- win10配置CUDA+Tensorflow2.0的一些经验
目录 问题描述 安装 tensorflow-cpu-2.0 编译 Nvidia Samples 问题描述 网上已经很多关于配置CUDA的文章,自己这篇文章只是个大致的安装步骤,文章重点是安装和配置的一 ...