hdu 5738 Eureka 极角排序+组合数学
Eureka
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2317 Accepted Submission(s): 678
A set P (P contains the label of the points) is called best set if and only if there are at least one best pair in P. Two numbers u and v (u,v∈P,u≠v) are called best pair, if for every w∈P, f(u,v)≥g(u,v,w), where f(u,v)=(xu−xv)2+(yu−yv)2−−−−−−−−−−−−−−−−−−√ and g(u,v,w)=f(u,v)+f(v,w)+f(w,u)2.
The first line contains an integer n (1≤n≤1000) -- then number of points.
Each of the following n lines contains two integers xi and yi (−109≤xi,yi≤109) -- coordinates of the i-th point.
3
1 1
1 1
1 1
3
0 0
0 1
1 0
1
0 0
3
0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf =0x7f7f7f7f;
const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=100000+10;
ll f_2[1000+10]; struct Point{
int x,y;
}p[1000+10]; struct Ang{
double a;
ll x,y;
}ang[1000+10]; bool cmpxy(Point a,Point b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
} bool cmpang(Ang a,Ang b){
return a.a<b.a;
} int main()
{
f_2[0]=1;
for(int i=1;i<=1000;i++) f_2[i]=(f_2[i-1]*2)%mod;
int cas,n;
scanf("%d",&cas);
while(cas--)
{
ll ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d %d",&p[i].x,&p[i].y);
sort(p+1,p+n+1,cmpxy); int i,j,k,l,num;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[j].x==p[i].x&&p[j].y==p[i].y) continue;
else break;
}
j--;
int s=j-i+1,cnt=0,d=0;
ans=(ans+f_2[s]-1-s)%mod;
for(k=j+1;k<=n;k++)
{
ang[++cnt].a=atan2((double)(p[k].y-p[i].y),(double)(p[k].x-p[i].x));
ang[cnt].x=p[k].x;
ang[cnt].y=p[k].y;
} sort(ang+1,ang+cnt+1,cmpang);
for(k=1;k<=cnt;k++){ for(l=k+1;l<=cnt;l++)
if((ang[l].y-p[i].y)*(ang[k].x-p[i].x)!=
(ang[k].y-p[i].y)*(ang[l].x-p[i].x))
{d++;break;}
l--;
num=l-k+1;
ans=(ans+((f_2[s]-1)*(f_2[num]-1))%mod)%mod;
k=l;
} i=j;
}
printf("%lld\n",ans%mod);
}
return 0;
}
思路:先对所有的点进行坐标排序,然后依次枚举每个点,先筛选出与其重合的点,然后,
再依次为基点,求得没有枚举过得点相对这个点的角度,再进行极角排序,合并共线的点(这个
判断共线容易错。不能直接根据相对基点角度(double型)是否相等来判断,可以直接用向量
共线的坐标,变成相乘的形式)
hdu 5738 Eureka 极角排序+组合数学的更多相关文章
- HDU 5738 Eureka(极角排序)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5738 [题目大意] 给出平面中一些点,在同一直线的点可以划分为一个集合,问可以组成多少包含元素不少 ...
- HDU 5738 Eureka 统计共线的子集个数
Eureka 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5738 Description Professor Zhang draws n poin ...
- HDU 5738 Eureka
传送门 题目大意: 给出平面上的$n$个点,每个点有唯一的标号($\text{label}$),这$n$个标号的集合记作$S$,点可能重合.求满足下列条件的$S$的子集$T$的数目: 1. $|T|\ ...
- hdu-5738 Eureka(组合计数+极角排序)
题目链接: Eureka Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pr ...
- 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...
- HDU Always Cook Mushroom (极角排序+树状数组)
Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mush ...
- 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)
题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...
- HDU 6538 Neko and quadrilateral(极角排序+旋转坐标系)
这道题简直太好了,对于计算几何选手需要掌握的一个方法. 首先对于求解四边形面积,我们可以将四边形按对角线划分成两个三角形,显然此时四边形的面积最大最小值就变成了求解里这个对角线最近最远的点对. 对于此 ...
- poj2280Amphiphilic Carbon Molecules(极角排序)
链接 卡了几天的破题,对于hdu的那份数据,这就一神题.. 借助极角排序,枚举以每一个点进行极角排序,然后构造两条扫描线,一个上面一个下面,两条同时走,把上线和下线的点以及上线左边的点分别统计出来,如 ...
随机推荐
- 了解WebSocket
了解WebSocket WebSocket协议是基于TCP的一种新的协议.WebSocket最初在HTML5规范中被引用为TCP连接,作为基于TCP的套接字API的占位符.它实现了浏览器与服务器全 ...
- X86逆向13:向程序中插入Dll
本章我们将学习Dll的注入技巧,我们将把一个动态链接库永久的插入到目标程序中,让程序在运行后直接执行这个Dll文件,这一章的内容也可以看作是第八课的加强篇,第八课中我们向程序中插入了一个弹窗,有木有发 ...
- Python库的优雅安装及PyCharm虚拟环境配置
一.安装python库 安装python库有几种方式: 1. 使用pip命令行,如:pip install Pillow 2. 在pycharm中安装 3. 使用Anaconda批量安装常用模块 在使 ...
- 牛客 132C 简单瞎搞题 (bitset)
大意: 给定序列$a$的第$i$个元素的取值范围$[L_i,R_i]$, 求$a$的平方和的种类数. 用bitset优化, 复杂度$O(\frac{n^5}{\omega})$ #include &l ...
- nignx简单介绍
Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...
- squoosh
谷歌在线压缩图片
- 1 sql server 中cursor的简介
1.游标的分类 游标共有3类:API服务器游标.Transaction-SQL游标和API客户端游标. 2 API服务器cursor共有如下几种 静态游标的完整结果集将打开游标时建立的结果集存储在临时 ...
- Idea破解2019
转自:https://blog.csdn.net/qq_36622149/article/details/88910952 Idea破解,亲测有效,轻量快捷高效更新记录:首次:Idea破解,亲测有效2 ...
- Perl数据类型
Perl 是一种弱类型语言,所以变量不需要指定类型,Perl 解释器会根据上下文自动选择匹配类型. Perl 有三个基本的数据类型:标量.数组.哈希.以下是这三种数据类型的说明: 标量 标量是Perl ...
- SokcetClient VC++6.0
// SokcetClient.cpp: implementation of the SokcetClient class. // ////////////////////////////////// ...