Description

A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating about its centre by 90 degrees gives the same polygon. It is not the only polygon with the latter property, however,
as a regular octagon also has this property. 



So we all know what a square looks like, but can we find all possible squares that can be formed from a set of stars in a night sky? To make the problem easier, we will assume that the night sky is a 2-dimensional plane, and each star is specified by its x
and y coordinates. 

Input

The input consists of a number of test cases. Each test case starts with the integer n (1 <= n <= 1000) indicating the number of points to follow. Each of the next n lines specify the x and y coordinates (two integers) of each point. You may assume that the
points are distinct and the magnitudes of the coordinates are less than 20000. The input is terminated when n = 0.

Output

For each test case, print on a line the number of squares one can form from the given stars.

Sample Input

4
1 0
0 1
1 1
0 0
9
0 0
1 0
2 0
0 2
1 2
2 2
0 1
1 1
2 1
4
-2 5
3 7
0 0
5 2
0

Sample Output

1
6
1
/*
Author: 2486
Memory: 24256 KB Time: 375 MS
Language: C++ Result: Accepted
*/
//此题目暴力暴力枚举
//通过已经确定好的两点,算出剩下的两点
//(有两种情况)
//一个在上面,一个以下
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=20000+5;
struct point{
int x,y;
}ps[1005];
int n,ans;
bool vis[maxn<<1][maxn<<1];
int main(){
while(~scanf("%d",&n),n){
ans=0;
for(int i=0;i<n;i++){
scanf("%d%d",&ps[i].x,&ps[i].y);
ps[i].x+=20000,ps[i].y+=20000;//在数组里面能够存储负数
vis[ps[i].x][ps[i].y]=true;//标记着这个点存在
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(i==j)continue;//分别代表着上下两种不同的正方形
int nx1=ps[i].x+ps[i].y-ps[j].y;
int ny1=ps[i].y+ps[j].x-ps[i].x;
int nx2=ps[j].x+ps[i].y-ps[j].y;
int ny2=ps[j].y+ps[j].x-ps[i].x;
if(vis[nx1][ny1]&&vis[nx2][ny2])ans++;
nx1=ps[i].x-(ps[i].y-ps[j].y);
ny1=ps[i].y-(ps[j].x-ps[i].x);
nx2=ps[j].x-(ps[i].y-ps[j].y);
ny2=ps[j].y-(ps[j].x-ps[i].x);
if(vis[nx1][ny1]&&vis[nx2][ny2])ans++;
}
}
for(int i=0;i<n;i++){
vis[ps[i].x][ps[i].y]=false;//必需要进行清零,不能用memset,由于数组有点大
}
printf("%d\n",ans/4);
}
return 0;
}

Squares-暴力枚举或者二分的更多相关文章

  1. CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)

    个人心得:开始拿着题目还是有点懵逼的,以前做过相同的,不过那是按一个位置行列全都反之,当时也是没有深究.现在在打比赛不得不 重新构思,后面一想把所有的状态都找出来,因为每次确定了已经按下的行和列后,按 ...

  2. poj 1753 Flip Game(暴力枚举)

    Flip Game   Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52279   Accepted: 22018 Des ...

  3. [Cqoi2015] 编号 【逆向思维,暴力枚举】

    Online Judge:Luogu-P4222 Label:逆向思维,暴力枚举 题目描述 你需要给一批商品编号,其中每个编号都是一个7位16进制数(由0~9, a-f组成).为了防止在人工处理时不小 ...

  4. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  5. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  6. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  7. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  8. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  9. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

随机推荐

  1. Django day24 cbv和APIView的源码分析 和 resful的规范

    一:cbv的源码分析 1.CBV和FBV的区别: - Class Base View   CBV(基于类的视图) - Function Base View   FBV(基于函数的视图) 2.as_vi ...

  2. go函数初级

    一.简介 在go语言中,函数的功能是非常强大的,以至于被认为拥有函数式编程语言的多种特性. 二.介绍 1.一个程序中包含了很多的函数:函数式基本的代码块 2.函数编写的顺序是无关紧要的:鉴于可读性的需 ...

  3. python 5:str(某一变量)(将其他数字解释为字符串)

    age = messege = "Your's age is " + str(age) #将其他数字更改为字符串 print(messege) 运行结果应该是: Your's ag ...

  4. C99新增内容之变长数组(VLA)

    我们在使用多维数组是有一点,任何情况下只能省略第一维的长度.比如在函数中要传一个数组时,数组的行可以在函数调用时传递,当属数组的列却只能在能被预置在函数内部.看下面一个例子: #define COLS ...

  5. POJ 3635 优先队列BFS

    (感谢lyd学长的幻灯片) 注意vis数组的应用 在vis[i][j]中 i表示到了第i个点 j表示还剩j升油 vis[i][j]表示最小话费. 这样只需搜到话费比它少的更新入堆就OK了 //By: ...

  6. ESB报文自动生成工具

    为了提高日常工作效率,自己在闲暇时间写了一款工具,功能界面如下图所示: 从ESB文档中复制报文字段.字段类型.报文字段注释,选择生成文件路径并输入文件名: 输入完毕后点击生成按钮,自动生成Contex ...

  7. 关于Core里的 StartUp里的方法的理解。

    public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; ...

  8. Java中面向对象三大特性之——继承

    继承的概述 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需再定义这些属性和行为,只要继承那一个类即可. 现实生活中继承:子承父业,用来描述事物之间的关系 代码中继承:就是用 ...

  9. js中的数组遍历

    js中的数组遍历是项目中经常用到的,在这里将几种方法做个对比. ! for循环:使用评率最高,也是最基本的一种遍历方式. let arr = ['a','b','c','d','e']; for (l ...

  10. 【剑指Offer】32、把数组排成最小的数

      题目描述:   输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323.   ...