HDU_5738 Eureka

Eureka

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3108    Accepted Submission(s): 881


Problem Description
Professor Zhang draws  n  points on the plane, which are conveniently labeled by  1,2,...,n . The  i -th point is at  (xi,yi) . Professor Zhang wants to know the number of best sets. As the value could be very large, print it modulo  109+7 .

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,vP,uv)  are called best pair, if for every  wP f(u,v)g(u,v,w) , where  f(u,v)=(xuxv)2+(yuyv)2  and  g(u,v,w)=f(u,v)+f(v,w)+f(w,u)2 .
 

Input
There are multiple test cases. The first line of input contains an integer  T , indicating the number of test cases. For each test case:

The first line contains an integer  n   (1n1000)  -- then number of points.

Each of the following  n  lines contains two integers  xi  and  yi   (109xi,yi109)  -- coordinates of the  i -th point.
 

Output
For each test case, output an integer denoting the answer.
 

Sample Input
  
  
3 3 1 1 1 1 1 1 3 0 0 0 1 1 0 1 0 0
 

Sample Output
  
  
4 3 0
 

Author
zimpha
 

Source

题意:
将 g(x) 用 f(x ) 代入后可得:
dis(u,v) > dis(u, w) + dis(w, v)
恰好是不能构成三角形的条件。故将题意转化如下:
二位平面上给定n个点,所有点互异且可能重合,从n个点中依次取出k个点(n=2, 3, ..., n),求满足所有点共线的取法(重点也算共线)共有多少种。

思路:首先预处理2的0到1000次方模1e9 + 7的值,再将所有点排序,排序后就很方便处理平行向量(包括相反向量),然后从第一个点依次往外扫,考虑每个点对总答案的贡献,每次处理一个点时,都将该点作为向量的起点:

1:只取与这个点重复的点组成集合,假设共有p点与这个点重合(不包括其本身),此时共有

C(p,1) + C(p,2) + ... +C(p,p) = 2^p - 1

种可能。

2:取以这个点为起点的向量共有多少个,假设以这点为起点且平行的向量共有q个,则重终点有q个,因为第一种情况只有重点,则这里必须至少有一个非零向量,而所有与这个点重合的点都是起点,则此时有

(C(p,0) + C(p,1) + ... + C(p,p)) * (C(q,1) + C(q,2) + ... +C(q,q)) = (2^p) * (2^q - 1)


种可能。

具体代码如下:


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MOD = 1e9 + 7;
const int MAXN = 1 << 10 + 7;
ll numPow[MAXN];       //numPow[i] = pow(2, i)

class Point
{
public:
        Point(){}
        Point(int a, int b) : x(a), y(b){}
        int x, y;
        bool operator<(const Point &p)const
        {
                return x == p.x ? y < p.y : x < p.x;
        }
}p[MAXN];

map<Point, int>vec;     //存放向量
map<Point, int>::iterator it;

void init()
{
        numPow[0] = 1;
        for(int i = 1; i < MAXN; ++i)
                numPow[i] = (numPow[i-1] * 2) % MOD;
}

int main()
{
        init();
        int t, n;
        scanf("%d", &t);
        while(t--)
        {
                ll ans = 0;
                scanf("%d", &n);
                for(int i = 0; i < n; ++i)
                {
                        scanf("%d%d", &p[i].x, &p[i].y);
                }
                sort(p, p+n);
                for(int i = 0; i < n-1; ++i)
                {
                      vec.clear();
                      int repeatPoint = 1; //重点个数
                      for(int j = i + 1; j < n; ++j)
                      {
                                if(p[i].x == p[j].x && p[i].y == p[j].y)
                                {
                                        repeatPoint++;
                                        continue;
                                }
                                int xx = p[j].x - p[i].x, yy = p[j].y - p[i].y;
                                int k = __gcd(xx, yy);
                                if(k) xx /= k, yy/= k;
                                vec[Point(xx, yy)]++;
                      }
                      if(repeatPoint > 1)       //存在重复点, 重复点组成的集合
                      {
                             ans = (ans + numPow[repeatPoint-1] - 1) % MOD;
                      }
                      for(it = vec.begin(); it != vec.end(); ++it)      //含有向量的集合
                      {
                              int vecNum = it->second;  //顶点p[i]为起点确定的向量总数
                              //该点有repeatPoint-1个重复点,从里面依次取0,1,2,...,repeatPoint-1个点(都看成是一个向量的起点)
                              //设该点是之后向量的起点则该点一定要取,然后从vecNum里面依次选择1,2,...,Vecnum个终点(平行向量)
                              ans += (((numPow[repeatPoint-1]) % MOD) * ((numPow[vecNum] - 1) % MOD)) % MOD;
                      }
                }
                printf("%lld\n", ans);
        }
        return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值