http://poj.org/problem?id=2002

题意:给出n组坐标,判断这些坐标能组成的正方形的个数。

思路:参考某大神的想法,先枚举两个点,然后利用公式表示出另外两个点,判断这两个点是否在这n组坐标中,其中查找另两个坐标用的set容器。

已知 (x1,y1)(x2,y2);

则:x3 = x1+(y1-y2); y3 = y1 -(x1-x2);

x4 = x2 +(y1-y2);y4 = y2 -(x1-x2);

或:x3 = x1 -(y1-y2);y3 = y1+(x1-x2);

x4 = x2 -(y1-y2);y4 = y2 +(x1-x2);

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
const int N=;
const int maxn=; using namespace std;
struct node
{
long long x;
long long y;
} p[maxn];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
int ans = ;
set<long long>tt;
for (int i = ; i < n; i ++)
{
scanf("%lld %lld",&p[i].x,&p[i].y);
tt.insert(p[i].x*N+p[i].y);//将坐标转化成一个数,坐标不同,则这个数就不同
}
for (int i = ; i < n; i ++)
{
int x1 = p[i].x;
int y1 = p[i].y;
for (int j = i+; j < n; j ++)
{
int x2 = p[j].x;
int y2 = p[j].y;
int x3 = x1+(y1-y2);
int y3 = y1-(x1-x2);
int x4 = x2+(y1-y2);
int y4 = y2-(x1-x2);
if (tt.count(x3*N+y3) && (tt.count(x4*N+y4)))// 查找坐标是否存在
++ans;
x3 = x1-(y1-y2);
y3 = y1+(x1-x2);
x4 = x2-(y1-y2);
y4 = y2+(x1-x2);
if (tt.count(x3*N+y3) && (tt.count(x4*N+y4)))
++ans;
}
}
printf("%d\n",ans/);
}
return ;
}

Squares(枚举+set 查找)的更多相关文章

  1. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  2. poj3977(折半枚举+二分查找)

    题目链接:https://vjudge.net/problem/POJ-3977 题意:给一个大小<=35的集合,找一个非空子集合,使得子集合元素和的绝对值最小,如果有多个这样的集合,找元素个数 ...

  3. Subset POJ - 3977(折半枚举+二分查找)

    题目描述 Given a list of N integers with absolute values no larger than 10 15, find a non empty subset o ...

  4. Subset---poj3977(折半枚举+二分查找)

    题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...

  5. POJ2002 Squares(枚举)

    题目链接. 分析: 普遍的做法是:先枚举两个点,通过数学公式得到另外2个点,使得这四个点能够成正方形.然后检查散点集中是否存在计算出来的那两个点,若存在,说明有一个正方形. 但这种做法会使同一个正方形 ...

  6. HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)

    主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...

  7. 4 Values whose Sum is 0(枚举+二分)

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  8. Android 千牛数据库分析

    标签(空格分隔): 千牛,逆向 问题:Android 千牛登陆后产生保存用户数据的db无法直接用sqlite3打开,需要解密. 反编译Apk后jd-gui查看源码.熟悉的sqlcrypto模块加密,阿 ...

  9. iOS - Share 分享/第三方登录

    1.系统方式创建分享 按照下图在 Info.plist 文件中将 Localization native development region 的值改为 China.如果不设置此项弹出的分享页面中显示 ...

随机推荐

  1. STL_优先队列_(转载)

    转自:http://www.cnblogs.com/summerRQ/articles/2470130.html STL容器之优先队列 优先级队列,以前刷题的时候用的比较熟,现在竟然我只能记得它的关键 ...

  2. Android Binder机制(一) Binder的设计和框架

    这是关于Android中Binder机制的一系列纯技术贴.花了一个多礼拜的时间,才终于将其整理完毕.行文于此,以做记录:也是将自己所得与大家分享.和以往一样,介绍Binder时,先讲解框架,然后再从设 ...

  3. PHP 之转换excel表格中的经纬度

    <?php set_time_limit(0); include './plugin/PHPExcel/PHPExcel.php'; include './plugin/PHPExcel/PHP ...

  4. enote笔记语言(4)(ver0.2)——“5w1h2k”分析法

    章节:“5w1h2k”分析法   what:我想知道某个“关键词(keyword)”(即,词汇.词语,或称单词,可以是概念|专业术语|.......)的定义. why:我想知道事物发生的原因.“why ...

  5. Eclipse中使用struts标签时出错

    原因是Action和ActionForm对应文件中没有继承相应的类,具体来说: ActionForm的编写: 必须继承org.apache.struts.action.ActionForm Actio ...

  6. Mysql - ORDER BY详解

    0 索引 1 概述 2 索引扫描排序和文件排序简介 3 索引扫描排序执行过程分析 4 文件排序 5 补充说明 6 参考资料 1 概述 MySQL有两种方式可以实现ORDER BY: 1.通过索引扫描生 ...

  7. Git 基础教程 之 多人协作

           多人协作时,从远程克隆时,默认情况下,只能看到master分支 git checkout -b dev origin/dev 创建远程origin的dev分支到本地 git branch ...

  8. Linux 实用指令(4)

    目录 实用指令 1.指定运行级别 2.切换到指定运行级别的指令 3.帮助指令 3.1man获得帮助信息 3.2help指令 4.文件目录类 4.1pwd指令 4.2 ls指令 4.3 cd指令 4.4 ...

  9. Vladik and Entertaining Flags

    Vladik and Entertaining Flags time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  10. map put

    public class test { static Map<String, Map<String, Integer>> mapB = new HashMap<Strin ...