Pagini recente » Cod sursa (job #728800) | Cod sursa (job #2522807) | Cod sursa (job #565159) | Cod sursa (job #1901187) | Cod sursa (job #768408)
Cod sursa(job #768408)
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
#define mod 1001
typedef struct {
int x;
int y;
} cutzu;
int N;
cutzu v[1005];
vector <cutzu> h[1005];
inline void Hashin (cutzu a) {
int lol = (a.x + a.y) % mod;
if (lol < 0) lol = -lol;
h[lol].push_back (a);
}
inline int Hashout (cutzu a) {
int n, lol = (a.x + a.y) % mod;
if (lol < 0) lol = -lol;
n = h[lol].size ();
for (int i = 0; i < n; i++)
if ((h[lol][i].x == a.x) && (h[lol][i].y == a.y)) return 1;
return 0;
}
void Citire () {
ifstream fin ("patrate3.in");
fin >> N;
char pars[100];
char dummy[10];
fin.getline (dummy, 7);
int j;
for (int i = 0; i < N; i++)
{
fin.getline (pars, 90);
for (j = 0; pars[j] != '.'; j++)
v[i].x = v[i].x * 10 + pars[j] - '0';
j++;
for (int k = j; k <= j + 3; k++)
v[i].x = v[i].x * 10 + pars[k] - '0';
for (j = j + 5; pars[j] != '.'; j++)
v[i].y = v[i].y * 10 + pars[j] - '0';
j++;
for (int k = j; k <= j + 3; k++)
v[i].y = v[i].y * 10 + pars[k] - '0';
Hashin (v[i]);
}
fin.close ();
}
int Business () {
int x3, y3, x2, y2, x1, y1;
int xm, xf0, xf1, ym, yf0, yf1, xlol, ylol, x1p, y1p, xp, yp;
int cnt = 0;
cutzu u, t;
for (int i = 0; i < N; i++)
{
for (int j = i + 1; j < N; j++)
{
if (v[i].y >= v[j].y) xlol = v[i].x, ylol = v[i].y, x1 = v[j].x, y1 = v[j].y;
else xlol = v[j].x, ylol = v[j].y, x1 = v[i].x, y1 = v[i].y;
yp = ylol - (xlol - x1);
y1p = y1 - (xlol - x1);
xp = xlol + (ylol - y1);
x1p = x1 + (ylol - y1);
u.x = xp;
u.y = yp;
t.x = x1p;
t.y = y1p;
if (Hashout (u) && Hashout (t)) cnt++;
}
}
return cnt >> 1;
}
void Scriere () {
ofstream fout ("patrate3.out");
fout << Business ();
fout.close ();
}
int main () {
Citire ();
Scriere ();
return 0;
}