https://www.codechef.com/problems/D6
The problem is: given a set of N points in the plane, how many squares are there such that all their corners belong to this set?
https://www.codechef.com/status/D6
https://www.codechef.com/viewsolution/10228421
The problem is: given a set of N points in the plane, how many squares are there such that all their corners belong to this set?
The first line contains t, the number of test cases (about 10). Then t test cases follow.
Each test case has the following form:
- The first line contains an integer N, the number of points in the given set (4 ≤ N ≤ 500).
- Then N lines follow, each line contains two integers X, Y describing coordinates of a point (-50 ≤ X, Y ≤ 50).
Output
For each test case, print in a single line the number of squares that have vertices belong to the given set.
Example
Input: 1 7 0 0 0 1 1 0 1 1 1 2 2 1 2 2 Output: 3 Output details: The three squares are: (0 0), (0 1), (1 1), (1 0) (1 1), (1 2), (2 2), (2 1) (0 1), (1 0), (2 1), (1 2)
https://www.codechef.com/viewsolution/10228421
- for (int i=0; i<n; i++) {
- List<Point> points = new ArrayList<Point>(k);
- Set<Point> set = new HashSet<Point>(2*k);
- for (int j=0; j<k; j++) {
- int index = s.indexOf(' ');
- points.add(p);
- set.add(p);
- }
- int count = 0;
- for (int x=0; x<k; x++) {
- for (int y=x+1; y<k; y++) {
- int dx = b.x-a.x;
- int dy = b.y-a.y;
- c.x = b.x-dy;
- c.y = b.y+dx;
- d.x = c.x-dx;
- d.y = c.y-dy;
- if (set.contains(c) && set.contains(d)) {
- count++;
- }
- c.x = b.x+dy;
- c.y = b.y-dx;
- d.x = c.x-dx;
- d.y = c.y-dy;
- if (set.contains(c) && set.contains(d)) {
- count++;
- }
- }
- }
- out.println(count/4);
- }
- out.close();
- }