题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5738

题目大意:给定平面上的n个点,一个集合合法当且仅当集合中存在一对点u,v,对于集合中任意点w,均有dis(u,v)≥[dis(u,v)+dis(u,w)+dis(v,w)]/2。其中dis(A,B)为A,B两点的欧几里得距离(?)。问你这样的合法集合有多少个。数据范围:1≤n≤1000。

提示:可能出现多个同样的点,我们称之为重点。

容易得到:n个点(其中有cnt个重复的p点)共线,可构成的集合$$2^{n}-C_{n}^{1}-C_{n}^{0}\tag1$$即$2^{n}-n-1$个。包括了“任意2个p点组成集合”这种情况。

但是 同时p点也与另外m个点共线,也可构成$2^{m}-n-1$,注意 其中也包括了 “任意2个p点组成集合”。这就重复记数了。如何规避重复,这也是题目的难点所在。

这里提供一种思路;

注意到,“只选择2个重点本身组成集合”对每个不同的重点,这种情况只能计数一次(在多种共线方案中只计数一次)。其他的共线方案中,

假设 有cnt 个重点 和 n个共线的点,采用分步计数方式,第一步在重点中选1个或多个点,第二步在n个点中选1个或多个点。这样的话,种数为

$$\left( 2^{cnt}-C_{cnt}^{0}\right) \ast \left( 2^{n}-C_{n}^{0}\right)\tag2$$

神奇的是,单个点(即cnt = 1),对 2 式也成立。即1个点也看作是重点。

如何实现:“对每个不同的重点,这种情况只能计数一次(在多种共线方案中只计数一次)”呢?   其实很好实现,即对每个重点,用公式 1 计数竖直共线情况即可。

对于其他的共线方案,通过极角排序,cmp() 的时候不要把斜率化成小数比较,直接dyA*dxB<dxA*dyB这样比较可避免精度问题。(为什么要除|gcd(dx,dy)|?难道是怕爆long long?表示目前还不知道)

总结,这道题目 需要的技巧比较多,细节也比较多,很哟挑战性!

代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL; const int MaxN = , Pt = 1e9 + ;
struct Point
{
int x, y, dx, dy;
} a[MaxN + ], b[MaxN + ];
int T, n;
LL Pow[MaxN + ];
LL ans; int Gcd(int x, int y)
{
if (y == ) return x;
return Gcd(y, x % y);
} void Init()
{
scanf("%d", &n);
Pow[] = ;
for (int i = ; i <= n; i++)
{
scanf("%d%d", &a[i].x, &a[i].y);
Pow[i] = (Pow[i - ] * ) % Pt;
}
} bool cmp(Point A, Point B)
{
if (A.x == B.x) return A.y < B.y;
return A.x < B.x;
} bool cmp2(Point A, Point B)
{
return (LL)A.dy * B.dx < (LL)A.dx * B.dy;
} void Solve()
{
ans = ;
sort(a + , a + n + , cmp);
int L = , R = ;
while (L <= n)
{
while (R < n && a[R + ].x == a[R].x) R++;
ans = (ans + Pow[R - L + ] - - (R - L + )) % Pt;
int l = L, r = L;
while (l <= R)
{
while (r < R && a[r + ].y == a[r].y) r++;
int tot = ;
for (int i = R + ; i <= n; i++)
{
b[++tot].dx = a[i].x - a[l].x;
b[tot].dy = a[i].y - a[l].y;
int D = Gcd(b[tot].dx, b[tot].dy);
if (D < ) D = -D;
b[tot].dx /= D;
b[tot].dy /= D;
}
sort(b + , b + tot + , cmp2);
int cnt = ;
for (int i = ; i <= tot; i++)
{
if (i == tot || cmp2(b[i], b[i + ]))
{
ans = (ans + (Pow[r - l + ] - ) * (Pow[cnt] - )) % Pt;
cnt = ;
}
else cnt++;
}
l = r + ;
r = r + ;
}
L = R + ;
R = R + ;
}
printf("%I64d\n", ans);
} int main()
{
scanf("%d", &T);
for (int i = ; i <= T; i++)
{
Init();
Solve();
}
}

2016 Multi-University Training Contest 2 - 1005 Eureka的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. hdu 4939 2014 Multi-University Training Contest 7 1005

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. 2016 Multi-University Training Contest 4 - 1005 (hdu5768)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5768 题目大意:给你区间[L,R],问你[L, R]中有多少个数字x满足x%7=0且x%p[i]≠a[ ...

  4. 2016 Multi-University Training Contest 2 - 1005 (hdu5738)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5738 题目大意:给定平面上的n个点,一个集合合法当且仅当集合中存在一对点u,v,对于集合中任意点w,均 ...

  5. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  6. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  7. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  8. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  9. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

随机推荐

  1. Best Practices for Performance_4.Optimizing Battery Life 获取充电状态、电池信息,"sticky"类型的广播

    http://developer.android.com/training/monitoring-device-state/index.htmlhttp://developer.android.com ...

  2. 开源共享一个训练好的中文词向量(语料是维基百科的内容,大概1G多一点)

    使用gensim的word2vec训练了一个词向量. 语料是1G多的维基百科,感觉词向量的质量还不错,共享出来,希望对大家有用. 下载地址是: http://pan.baidu.com/s/1boPm ...

  3. json对象数组按对象属性排序

    var array = [ {name: 'a', phone: 1, value: 'val_4'}, {name: 'b', phone: 5, value: 'val_3'}, {name: ' ...

  4. [Maven]Maven 那点事儿

    0. 前言 Jason Van Zyl,在 Java 十大风云人物排行榜上或许会看到他. 这兄弟是干嘛的? 他就是 Maven 的创始人,人们都尊称他为"Maven 他爸". 毋庸 ...

  5. eclispe中在线安装maven插件

    启动Eclipse之后,在菜单栏中选择Help,然后选择Install New Software-,接着你会看到一个Install对话框, 点击Work with:字段边上的Add按钮,你会得到一个新 ...

  6. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  7. HDNOIP201405杨辉三角

    2016.1.27 试题描述 杨辉三角是形如如下的数字三角形: 1 1    1 1   2    1 …… 现在想求出杨辉三角第N行的N个数中,有多少个数能被给定的质数p整除. 输入 一行两个空格隔 ...

  8. 规则引擎集成接口(九)Java类对象

    Java类对象 右键点击“对象库” —“添加java类对象”,如下图: 弹出窗体,在文本框中输入类的全名“com.flagleader.test.Test”,选择该类型后确定,如下: 显示如下,勾选上 ...

  9. C# 6.0可能的新特性及C#发展历程

    据扯,C# 6.0在不远的将来就发布了,对应的IDE可能是VS 2014(.Net Framework 5.0),因为VS 2013已于2013年10月份发布了,对应的是.Net Franework ...

  10. qt 环境下mapx组件的鼠标跟踪

    经过两天的研究mapx组件人坐标转换还是没有转换成功,因为不管怎么变,定点转换的经纬度坐标始终与期望的值有较大的偏差.最后还是想老大请教了一下,划了半天功夫就研究出来了(不愧是老大,仰慕之情犹如滔滔江 ...