题目链接: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。

解题思路:对于所给条件简单分析一下就能转化题意,实际上是在求有多少个集合满足集合内的点都在同一直线上。

比赛时的思路一直是,由于可能有重点,于是把重点整合到一个集合里,记一下集合里的个数cnt,那么对于这样一个重点的集合,从中任选至少两个都能作为合法点集,因此对答案的贡献是(2^cnt - cnt - 1)。下面考虑非重点,枚举重点集,对其他重点集按到此点集的距离从小到大排序,再依次枚举,用map记录一下斜率,就能在枚举过程中得到两个重点集之间的点个数K(也就是有多少个点也是这个斜率),对答案的贡献就是(2^cnt1 - 1)*(2^cnt2 - 1)*(2^K)。这样做思路应该没什么问题,只是常数比较大,代码难度也不小。一直到比赛结束也一直WA。

后来看了题解,思路比较清楚。对于这种数方案,要不重不漏的题目要记得使用有序化思想。而在二维坐标中,很常用的两种排序就是x,y双关键字排序,还有极角排序。

首先我们对这n个点做双关键字排序,然后对于x相同的点,个数为cnt,那么对答案的贡献就是(2^cnt - cnt - 1),然后对于每个重点集,对它右面的点做极角排序,做这个排序的意义在于以下就把同一斜率的点搞到了一起,方便计算了。假设当前极角上有p个点那么对答案的贡献就是(2^cnt - 1)*(2^p - 1)。

值得注意的也是十分重要的,就是极角排序的正确做法。首先计算dx, dy,并除掉abs(gcd(dx,dy)),一定要取绝对值!!不然会WA得不明所以!!然后cmp()的时候不要把斜率化成小数比较,直接dyA*dxB<dxA*dyB这样比较可避免精度问题。

总之这道题思想难度不是很大,但是需要的技巧比较多,细节也比较多,是值得一写的题目。

 #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++;
//printf("%d %d\n", L, 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++;
//printf("**%d %d\n", l, 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 (hdu5738)的更多相关文章

  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 2 - 1005 Eureka

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

  4. 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[ ...

  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. day34 协程

    1.   前提 之前我们学习了线程.进程的概念,了解了在操作系统中进程是资源分配的最小单位,线程是CPU调度的最小单位.按道理来说我们已经算是把cpu的利用率提高很多了.但是我们知道无论是创建多进程还 ...

  2. Linux系统调用接口添加简单示例

    1. Linux体系结构 Linux系统的地址空间分为用户空间和内核空间,通过系统调用和硬件中断能够完成从用户空间到内核空间的转移. 2. 系统调用接口 ① 一般情况下,用户进程不能访问内核空间.Li ...

  3. SSL证书切换

    SSL证书:SSL证书是数字证书的一种,类似于驾驶证.护照和营业执照的电子副本.因为配置在服务器上,也称为SSL服务器证书.SSL 证书就是遵守 SSL协议,由受信任的数字证书颁发机构CA,在验证服务 ...

  4. JS 中Math.ceil()、Math.floor()和Math.round()的区别

    var arg1 = 12.2; var arg2 = 12.5; var arg3 = 12.7; ceil():将小数部分一律向整数部分进位 var c1 = Math.ceil(arg1); v ...

  5. 关系型数据库---MySQL---事务

    1.概述 1.1 事务:在对业务相关的一系列数据进行操作时,需要保证数据操作的完整性(要么全部成功.要么全部失败): 1.2 MySQL中支持事务的存储引擎是:Innodb: 1.3 事务用来管理in ...

  6. springboot 启动的java进程默默终止

    首先说明这是一个灵异事件......... 场景1 :把之前用map实现的缓存用Redis重构,高高兴兴上线更新,10 分钟后,老板告诉我,项目停了,what ??? 像我这么帅气,英俊,聪明的人,更 ...

  7. HDU - 6208 The Dominator of Strings HDU - 6208 AC自动机 || 后缀自动机

    https://vjudge.net/problem/HDU-6208 首先可以知道最长那个串肯定是答案 然后,相当于用n - 1个模式串去匹配这个主串,看看有多少个能匹配. 普通kmp的话,每次都要 ...

  8. Windows64bit-plsqldeveloper-install the easiest way

    The easiest way to add a 32 Bit Oracle Client: 1.Download the Oracle 11g or 12c Instant Client(http: ...

  9. Murano Weekly Meeting 2016.06.07

    Meeting time: 2016.June.7 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: 1.A ...

  10. LeetCode 454.四数相加 II(C++)

    给定四个包含整数的数组列表 A , B , C , D ,计算有多少个元组 (i, j, k, l) ,使得 A[i] + B[j] + C[k] + D[l] = 0. 为了使问题简单化,所有的 A ...