栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3432 Count Squares

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3432 Count Squares

#include <iostream>#include <algorithm>#include <stdio.h>using namespace std;const int N=2002;struct m_point{    int x,y;};int n;m_point p[N];bool cmp(const m_point &p1,const m_point &p2){    if(p1.x < p2.x)        return true;    if((p1.x == p2.x) && (p1.y < p2.y))        return true;    return false;}bool find_point(m_point &t){    int left=0,right=n,mid;    while(left<=right)    {        mid=(left+right)>>1;        if((p[mid].x == t.x) && (p[mid].y == t.y)) return true;        if(cmp(t,p[mid])) right=mid-1;        else left=mid+1;    }    return false;}int main(){    int i,j,ans;    m_point tmp,new_node;    while(scanf("%d",&n) != EOF)    {        for(i=0;i<n;++i) scanf("%d%d",&p[i].x,&p[i].y);        sort(p,p+n,cmp);        ans=0;        for(i=0;i<n;++i)        { for(j=i+1;j<n;++j) {     tmp.x=p[j].x-p[i].x;     tmp.y=p[j].y-p[i].y;     new_node.x=p[i].x+tmp.y;     new_node.y=p[i].y-tmp.x;     if(!find_point(new_node))         continue;     new_node.x=p[j].x+tmp.y;     new_node.y=p[j].y-tmp.x;     if(!find_point(new_node))         continue;     ++ans; }        }        printf("%dn",ans/2);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373666.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号