18.12.20 DSA 正方形

描述

输入

包括多组数据,每组数据的第一行是整点的个数n(1<=n<=1000),其后n行每行由两个整数组成,表示一个点的x、y坐标。输入保证一组数据中不会出现相同的点,且坐标的绝对值小于等于20000。输入以一组n=0的数据结尾。输出对于每组输入数据,输出一个数,表示这组数据中的点可以组成的正方形的数量。

样例输入

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

样例输出

1
6
1

提示

40%的数据,坐标绝对值小于等于1000

来源

Rocky Mountain 2004

 1 #include <iostream>
 2 #include <string.h>
 3 #include <algorithm>
 4 #include <stack>
 5 #include <string>
 6 #include <math.h>
 7 #include <queue>
 8 #include <stdio.h>
 9 #include <string.h>
10 #include <set>
11 #include <vector>
12 #include <fstream>
13 #define maxn 200005
14 #define inf 999999
15 #define cha 127
16 #define eps 1e-6 
17 #define oo 1503
18 using namespace std;
19 
20 struct node {
21     int x, y;
22     node(int xx, int yy) :x(xx), y(yy) {  }
23     node() {  }
24 };
25 node Hash[2003];
26 node all[1003];
27 bool visited[2003];
28 int n;
29 
30 bool findval(node val) {
31     int first = ((val.x*val.x) % oo + (val.y*val.y) % oo) % oo;
32     while (Hash[first].x != val.x || Hash[first].y != val.y) {
33         if (visited[first]==false)return 0;
34         first++;
35     }
36     return 1;
37 }
38 
39 void insert(node val) {
40     int first = ((val.x*val.x) % oo + (val.y*val.y) % oo) % oo;
41     while (visited[first])
42         first++;
43     Hash[first] = val;
44     visited[first] = true;
45 }
46 
47 void init() {
48     memset(Hash, 0, sizeof(Hash));
49     memset(visited, 0, sizeof(visited));
50     for (int i = 1; i <= n; i++) {
51         scanf("%d%d", &all[i].x, &all[i].y);
52         insert(all[i]);
53     }
54     int ans = 0;
55     for(int i=1;i<=n;i++)
56         for (int j = 1; j <= n; j++) {
57             if (i == j)continue;
58             int x1, x2, y1, y2;
59             int xg = all[j].x - all[i].x, yg = all[j].y - all[i].y;
60             x1 = all[i].x - yg, x2 = x1 + xg;
61             y1 = all[i].y + xg, y2 = y1 + yg;
62             if (findval(node(x1, y1)) && findval(node(x2, y2)))
63                 ans++;
64         }
65     printf("%d\n", ans/4);
66 }
67 
68 int main() {
69     while(scanf("%d",&n)&&n)
70         init();
71     return 0;
72 }
View Code

直接贴原来的代码结果WA了……

果然MOOC数据太水

猜你喜欢

转载自www.cnblogs.com/yalphait/p/10150716.html
dsa