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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 使用 GitHub Actions 实现 Hexo 博客自动部署
一.Hexo 相关知识点 静态博客简单,但是发布博文时稍显麻烦,一般需要下面两步: hexo clean hexo g -d // 相当于 hexo g + hexo d 如果考虑到同步源文件,还需要 ...
- 【题解】P1908 逆序对——归并算法
先吐槽 这题做了两天,昨天讲分治,老师用归并讲了一遍,今天又用树状数组讲了一遍 归并不难,啊啊啊我居然才调出来 思路 归并两个数组时,对于第二个数组的元素a[c2],它与第一个数组中目前还没归到总数组 ...
- Visual Studio 2015 配置 Python 环境
Visual Studio 2015可以在安装时选择安装Python环境,首次使用VS2015执行python时需要配置环境变量: 配置VS2015的环境前需要先下载Python并安装: https: ...
- centos下升级php到5.6
今天正好用空把php环境升级到5.6版本,首先我之前的环境是源码包编译的lnmp环境 首先到php官方网站上下载一个php5.6的tar包,放到机器上面后,开始安装,安装前先将nginx,mysql, ...
- qt creator源码全方面分析(2-5)
目录 Creating Wizards in Code 介绍 相关类 IWizardFactory的设置器和获取器 Creating Wizards in Code 介绍 如果基于模板的自定义向导提供 ...
- finalize的用法
public class GC { public static GC SAVE_HOOK = null; public static void main(Strin ...
- chkcongfig 命令
chkconfig 命令主要用来 更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig ...
- nCompass-网络流量基础知识
nCompass-网络流量基础知识 1. 流量分析基础知识 1.1 常见的流量分析方式: SNMP: 网管平台通过主动式获取设备接口流量信息. Flow:网络设备将穿越的数据流信息精简压缩打包. ...
- F——宋飞正传(HDU3351)
题目: I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simpl ...
- 使用Gradle推送SpringBoot项目源码到私有仓库
应用场景: 在SpringCloud微服务项目中,通常会划分成多个业务服务,而这些服务之间一般会使用Feign组件进行相互调用,所以在项目开发中会衍生出一个问题:Feign客户端代码该由服务调用方的开 ...