The main topic: give you n points, ask that n points can be composed of the maximum number of parallelogram.
Topic idea: This problem card time, and card memory. You have to try to optimize as much as possible.
The judgment theorem of parallelogram:
- The four sides of the two groups are parallel to each other by parallelogram (definition method).
- A set of parallel and equal four-sided shapes is parallelogram;
- The four sides of the two groups were equal to each other and parallelogram;
- The two groups of diagonally equal four-sided quadrilateral are parallelogram (two pairs of sides parallel judgment);
- The four-sided diagonal lines are parallelogram.
This problem is judged by theorem 5.
The midpoint coordinates of each edge are recorded, and if the midpoint coordinates of the two edges are the same, the two edges are shown to be a parallelogram two diagonal line.
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define INF 0x3f3f3f
#define MAX 1000005
using namespace std;
struct node
{
double midx, midy;
int x, y;
} Map [MAX];
int cmp (node A, node B)
{
if (A.midx! = B.midx)
return A.midx> B.midx;
return A.midy> B.midy;
}
int main ()
{
int T, n, i, j, num = 1, k;
long long sum, cnt, q;
scanf ("% d", & T);
while (T--)
{
sum = 0;
cnt = 0;
scanf ("% d", & n);
for (i = 1; i <= n; i ++)
{
scanf ("% d% d", & Map [i] .x, & Map [i] .y);
}
for (i = 1; i <= n; i ++)
{
for (j = i + 1; j <= n; j ++)
{
Map [cnt] .midx = (Map [i] .x + Map [j] .x) /2.0;
Map [cnt ++]. Midy = (Map [i] .y + Map [j] .y) /2.0;
}
}
sort (Map, Map + cnt, cmp); // To save time in subsequent operations, sort first
i = 0;
k = 0;
q = 1;
while (i <cnt)
{
if (Map [i] .midx == Map [k] .midx && Map [i] .midy == Map [k] .midy && k! = i)
{
sum + = q; // The newly added edge can form a new parallelogram with every previous edge with the same midpoint
q ++;
}
else if (Map [i] .midx! = Map [k] .midx || Map [i] .midy! = Map [k] .midy)
{
k = i;
q = 1;
}
i ++;
}
printf ("Case% d:% lld \ n", num ++, sum);
}
return 0;
}
The judgment theorem of Lightoj 1058 parallelogram