2016 Multi-University Training Contest 2 - 1005 Eureka
题目链接: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的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 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/ ...
- 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[ ...
- 2016 Multi-University Training Contest 2 - 1005 (hdu5738)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5738 题目大意:给定平面上的n个点,一个集合合法当且仅当集合中存在一对点u,v,对于集合中任意点w,均 ...
- 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 ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- asp.net解决高并发的方案.[转]
最近几天一直在读代震军的博客,他是Discuz!NT的设计者,读了他的一系列关于Discuz!NT的架构设计文章,大呼过瘾,特别是Discuz!NT在解决高访问高并发时所设计的一系列方案,本人尤其感兴 ...
- sql server 替换特殊符号
--create-- 去掉特殊符号alter function RepSymbol(@str nvarchar(max))returns nvarchar(max)as begin set @str= ...
- day3 字典,集合,文件
一.深浅copy 浅copy只copy第一层,不copy第二层.copy后,第一层指向不同内存地址.第二层指向相同的内存地址. 导入copy模块,deepcopy深copy.deepcopy后,均指向 ...
- sql server 跨数据库插入数据
创建服务器的连接,创建好后可以存在服务器上,可以在不同位置重复使用,和系统函数类似 exec sp_addlinkedserver 'RemoteServer', '', 'SQLOLEDB ', ' ...
- 《C#编程》
第一天做C#,第一个C#.2016-11-11,周五 1.是用windowFormApp编程的代码. 2.下面是ConsoleApp编程的代码 例题1.主要是声明变量,1>使用变量,赋值语句 2 ...
- java关于值传递和引用传递的有趣试验
上代码: public class Demo { public static void main(String[] args) { test_1(); test_2(); } public stati ...
- Linux下的文件与目录操作 BY 四喜三顺
文件操作权限: chmod 三个八进制数字 文件名 其中:三个八进制数字,第一个代表本用户的权限,第二个代表同组的权限,第三个代表其他用户的权限4代表可读2代表可写1代表可执行例如:chmod 7 ...
- 可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能)
原地址: http://www.cnblogs.com/yk250/p/5660340.html 效果图如下:支持分组的单选框,复选框样式和MVVM下功能的实现.这是项目中一个快捷键功能的扩展. 1, ...
- backtrack下vim的使用
root@bt:~# vim test.c //vim新建或者编辑test.c,执行后进入vim编辑器,按a键进入编辑状态,输入C代码 #include<stdio.h> void mai ...
- iOS 三种定时器
http://www.cocoachina.com/ios/20160905/17482.html