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. golang单点推送

    package main import ( "encoding/json" "flag" "fmt" "log" &qu ...

  2. Spring的AOP机制---- AOP环绕通知---- AOP环绕通知

    323232三个人个地方司法发送哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈

  3. .net MVC成长记录(二)

    今天上班的任务完成了,接下来写一下博客,巩固一下,再学习一些新知识. 闲话不多说,我们言归正传.昨天讲到了如何mvc框架在微软下,已经变成了一个非常灵活非常‘干净’的开发框架了, 同时也讲述了如何创建 ...

  4. Microsoft SQL Server 2005技术内幕:T-SQL查询笔记

    logical operation:基于微软查询处理概念模型的逻辑操作.例如,联接运算符的physical operation属性表示联接算法(nested loops,merge ,hash)物理运 ...

  5. 【Oracle】进入sqlplus 删除键backspace时出现^H

    当oracle进入sqlplus后,输入命令时候出现错误,我们按平时的习惯使用backspace键删除错误信息,此时会出现^H 解决办法:进入sqlplus之前,使用stty erase '^H'命令 ...

  6. node 连接MySQL及其分装, 连接池连接

    const mysql = require('mysql') const config = require('./../../config/config.default') var connectio ...

  7. Deutsch lernen (15)

    1.    unterscheiden - unterschied - unterschieden  区别,区分:(能够)分清 Die beiden Begriffe sind nur schwer ...

  8. jenkins如何实现重新发布历史构建记录里的版本

    Jenkins以前打包都会将打出的拷贝放到历史版本里放到Daily_Result里,昨天不只是误操作还是系统问题,误将一个历史版本的包删掉了,而且这个包是之前比较稳定的一个版本,需要重新给客户发,所以 ...

  9. 时序分析:ARMA方法(平稳序列)

    憔悴到了转述中文综述的时候了........ 在统计学角度来看,时间序列分析是统计学中的一个重要分支, 是基于随机过程理论和数理统计学的一种重要方法和应用研究领域.  时间序列按其统计特性可分为平稳性 ...

  10. Python学习①. 基础语法

    Python 简介 Python 是一种解释型,面向对象的语言.特点是语法简单,可跨平台 Python 基础语法 交互式编程 交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编 ...