2016 多校2 1005 计数

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,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.

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 (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.

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

比赛时候我zz地用了一种sb的计数方案到死也没有调出来。赛后用了大涛哥的方案很快就过了。其实只需要枚举选中某个点的情况依次删去这些点就ok了。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int n;
struct node{
    int x, y;
}rec[1050];
int gcd(int x, int y)
{
    if(x==0)return y;
    else return gcd(y%x, x);
}
bool operator ==(node const&a, node const&b)
{
    return a.x==b.x&&a.y==b.y;
}
bool operator <(node const&a, node const&b)
{
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
node operator -(node const&a, node const&b)
{
    node ans;
    ans.x=a.x-b.x;ans.y=a.y-b.y;
    int tmp=abs(gcd(ans.x, ans.y));
    ans.x/=tmp;ans.y/=tmp;
    if(ans.x<0){
        ans.x=-ans.x;ans.y=-ans.y;
    }
    else if(ans.x==0)ans.y=abs(ans.y);
    return ans;
}
ll Pow(ll base, int b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*base)%mod;
        }
        base=(base*base)%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        ll ans=0;
        scanf("%d", &n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d", &rec[i].x, &rec[i].y);
        }
        for(ll i=1;i<=n;i++)
        {
            map<node, int>mp;
            int cnt=0;
            for(ll j=i+1;j<=n;j++)
            {
                if(rec[j]==rec[i]){
                    cnt++;
                    continue;
                }
                else {
                    node tmp=rec[j]-rec[i];
                    mp[tmp]++;
                }
            }
            ans+=Pow(2, cnt)-1+mod;
            ans%=mod;
            for(map<node, int>::iterator it=mp.begin();it!=mp.end();it++)
            {
                int p=it->second;
                ans=(ans+(Pow(2, cnt)*((Pow(2, p)-1+mod)%mod))%mod)%mod;
            }
        }
        printf("%lld\n", ans);
    }
}``
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值