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;
    }
  • 相关阅读:
    UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
    关于自定义导航条UIBarButtonItem偏移的问题
    iOS端使用二维码扫描(ZBarSDK)和生成(libqrencode)功能
    CocoaPods安装和使用教程
    IOS中NSUserDefaults的用法(轻量级本地数据存储) (转)
    UIPickerView简单选择器的基本使用
    [原]Unity手游之路&lt;三&gt; 基于Unity+Java的聊天室源码
    [原]UML建模语言进阶
    [原]Java多线程编程学习笔记之九:使用wait/notify/notifyAll实现线程间通信的几点说明
    [原]MySQL的表分区
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5370491.html
Copyright © 2011-2022 走看看