星星
来源:互联网 发布:手机如何装修淘宝店铺 编辑:程序博客网 时间:2024/04/27 13:22
Problem Description
Lucy loves stars very much. There are N (1 <= N <= 1000) stars in the sky. Assume the sky is a flat plane. All of the stars lie on it with a location (x, y), -10000 <= x, y <= 10000. Now, Lucy wants you to tell her how many squares with each of four vertices formed by these stars, and the edges of the squares should parallel to the coordinate axes.
Input
The first line of input is the number of test case.
The first line of each test case contains an integer N. The following N lines each contains two integers x, y, meaning the coordinates of the stars. All the coordinates are different.
Output
For each test case, output the number of squares in a single line.
Sample Input
2
1
1 2
4
0 0
1 0
1 1
0 1
Sample Output
0
Lucy loves stars very much. There are N (1 <= N <= 1000) stars in the sky. Assume the sky is a flat plane. All of the stars lie on it with a location (x, y), -10000 <= x, y <= 10000. Now, Lucy wants you to tell her how many squares with each of four vertices formed by these stars, and the edges of the squares should parallel to the coordinate axes.
Input
The first line of input is the number of test case.
The first line of each test case contains an integer N. The following N lines each contains two integers x, y, meaning the coordinates of the stars. All the coordinates are different.
Output
For each test case, output the number of squares in a single line.
Sample Input
2
1
1 2
4
0 0
1 0
1 1
0 1
Sample Output
0
1
#include<stdio.h>#include<cmath>#include<string.h>#include<iostream>#include<algorithm>using namespace std;struct point{int x,y;}p[1003];bool cmp(point p1,point p2){if(p1.x==p2.x) return p1.y<p2.y;else return p1.x<p2.x;}bool search(int l,int r,int x,int y){int left,right,mid;left=l;right=r;while(left<=right){mid=(left+right)>>1;if(p[mid].x==x&&p[mid].y==y)return true;if(p[mid].x<x)left=mid+1;else if(p[mid].x>x)right=mid-1;else if(p[mid].y<y)left=mid+1;else if(p[mid].y>y)right=mid-1;}return false;}int main(){//freopen("b.txt","r",stdin);int cases,n,i,cnt=0,j;scanf("%d",&cases);while(cases--){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d %d",&p[i].x,&p[i].y);sort(p,p+n,cmp);cnt=0;for(i=0;i<n-1;i++)for(j=i+1;j<n;j++){if(abs(p[j].x-p[i].x)==abs(p[j].y-p[i].y)){//printf("%d %d %d %d\n",p[i].x,p[j].y,p[j].x,p[i].y);if(search(i,j,p[i].x,p[j].y)&&search(i,j,p[j].x,p[i].y))cnt++;}}printf("%d\n",cnt);}return 0;}
0 0
- 星星
- 星星!
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星
- 星星星星星星
- 第九周项目三小星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星星
- 星星星星(2)......
- 五个星星
- Android Service的用法
- POJ 2828 Buy Tickets
- 【归并排序】求逆序对的时候顺手写的,于是就顺手贴了,于是标题就长了
- Lua语言学习之错误与异常
- uva1160X-Plosives并查集
- 星星
- hdu2444 The Accomodation of Students
- lightoj 1170 Counting Perfect BST
- 函数 形参和实参
- Java中的设计模式,书籍推荐
- UITableViewCell重用机制
- 外包公司框架搭建需要注意的几点
- 浮躁病
- CentOS下使用RPM安装MySQL出现file ... conflicts with file ...提示后没有反应的解决方法。