Mai intai trebuie sa te autentifici.
Cod sursa(job #7704)
Utilizator | Data | 21 ianuarie 2007 23:39:13 | |
---|---|---|---|
Problema | Patrate 3 | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 2.18 kb |
#include <stdio.h>
#include <set>
using namespace std;
#define NMAX 1010
int N;
set <pair<int, int> > H;
pair <int, int> a[NMAX];
int beg;
char s[100];
int gen(int N)
{
freopen("patrate3.in", "w", stdout);
printf("%d\n", N);
for (int i = 1; i <= N; i++)
printf("%d.%d %d.%d\n", rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000);
fclose(stdout);
return 0;
}
int GET()
{
int q = 0;
for (; s[beg] && '0' <= s[beg] && s[beg] <= '9'; beg++)
q = q * 10 + s[beg] - '0';
return q;
}
void SKIP()
{
for (; s[beg] && s[beg] == ' '; beg++);
}
int main()
{
// gen(1000);
int x, x1, y, y1, xx, yy, xp, yp, x1p, y1p, i, j;
freopen("patrate3.in", "r", stdin);
freopen("patrate3.out", "w", stdout);
scanf("%d", &N);
for (i = 1; i <= N; i++) {
//scanf("%d.%d %d.%d", &x, &x1, &y, &y1);
fgets(s, 100, stdin);
beg = 0;
int e = 0, e1 = 0;
if (s[beg] == '-') e = 1, beg++;
x = GET();
beg++;
x1 = GET();
SKIP();
if (s[beg] == '-') e1 = 1, beg++;
y = GET();
beg++;
y1 = GET();
if (!e) xx = x * 10000 + x1;
else xx = (-x) * 10000 - x1;
if (!e1) yy = y * 10000 + y1;
else yy = (-y) * 10000 - y1;
// xx = x; yy = y;
a[i] = make_pair(xx, yy);
H.insert(make_pair(xx, yy));
}
int nr = 0;
// int nr1 = 0;
for (i = 1; i <= N; i++)
for (j = i + 1; j <= N; j++) {
if (a[i].second >= a[j].second) x = a[i].first, y = a[i].second, x1 = a[j].first, y1 = a[j].second;
else x = a[j].first, y = a[j].second, x1 = a[i].first, y1 = a[i].second;
yp = y - (x - x1);
y1p = y1 - (x - x1);
xp = x + (y - y1);
x1p = x1 + (y - y1);
// printf("%d %d | %d %d | %d %d | %d %d\n", x, y, x1, y1, xp, yp, x1p, y1p);
if (H.find(make_pair(xp, yp)) != H.end() && H.find(make_pair(x1p, y1p)) != H.end()) {
// printf("%d %d | %d %d | %d %d | %d %d\n", x, y, x1, y1, xp, yp, x1p, y1p);
nr++;
}
/* yp = y + (x - x1);
y1p = y1 + (x - x1);
xp = x - (y - y1);
x1p = x1 - (y - y1);
if (H.find(make_pair(xp, yp)) != H.end() && H.find(make_pair(x1p, y1p)) != H.end()) nr1++;
*/
}
// if (nr != nr1) while (1);
// if (nr & 1) while (1);
printf("%d\n", nr / 2);
// printf("%d\n", nr1);
fclose(stdin);
fclose(stdout);
return 0;
}