zoukankan      html  css  js  c++  java
  • codeforces 660D D. Number of Parallelograms(计算几何)

    题目链接:

    D. Number of Parallelograms

    time limit per test
    4 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.

    Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.

    Output

    Print the only integer c — the number of parallelograms with the vertices at the given points.

    Example
    input
    4
    0 1
    1 0
    1 1
    2 0
    output
    1


    题意:

    给了这么些点,问能形成多少个平行四边形;

    思路:

    把所有的线段找出来,按长度排序,平行四边形对边长度相等且互相平行,然后判断一下就好了,我的由于每个都算了4遍,所以最后/4;
    比赛还没完我就写题解了,说不定还要被hack,好方,哈哈哈哈;

    AC代码:

    /*
    2014300227    660D - 4    GNU C++11    Accepted    468 ms    80348 KB
    */
    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e6+20;
    typedef long long ll;
    const double PI=acos(-1.0);
    int n,cnt=1,vis[4*N];
    ll x[2005],y[2005];
    struct Line
    {
        int fi,se;
        ll le;
    };
    Line line[4*N];
    int cmp(Line a,Line b)
    {
        return a.le<b.le;
    }
    int findpos(ll num)
    {
        int l=1,r=cnt-1,mid;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(line[mid].le<num)l=mid+1;
            else r=mid-1;
        }
        return l;
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d%I64d",&x[i],&y[i]);
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                line[cnt].fi=i;
                line[cnt].se=j;
                line[cnt++].le=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            }
        }
    
        sort(line+1,line+cnt,cmp);
        vis[1]=1;
        for(int i=2;i<cnt;i++)
        {
            if(line[i].le==line[i-1].le)
            {
                vis[i]=vis[i-1];
            }
            else vis[i]=i;
        }
        int ans=0;
        for(int i=1;i<cnt;i++)
        {
            int pos=vis[i];
            for(int j=pos;j<cnt;j++)
            {
                if(line[j].le>line[i].le)break;
                if(line[j].fi==line[i].se||line[j].se==line[i].fi||line[j].fi==line[i].fi||line[j].se==line[i].se)continue;
                int cx,cy,dx,dy;
                cx=line[i].fi;
                cy=line[i].se;
                dx=line[j].fi;
                dy=line[j].se;
                if((x[cx]-x[cy])*(y[dx]-y[dy])==(y[cx]-y[cy])*(x[dx]-x[dy]))
                ans++;
            }
        }
        cout<<ans/4<<"
    ";
    
        return 0;
    }
  • 相关阅读:
    刚才遇到了关于C#使用外部DLL函数上的char*的问题。
    重新整理过的 《C#编码规范》
    晕,完全晕了。
    Microsoft Visual Studio 2010 支持html5和css3的补丁包
    [mysql] 修改root密码和查看连接数
    Visual Studio统计有效代码行数
    [c#] 邮件附件为中文名的bug
    游戏名词解释
    [SVN] 以下后缀文件不应该提交入库
    [c#] 语言新特性
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5370491.html
Copyright © 2011-2022 走看看