Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <cstring>
- #include <vector>
- #include <map>
- using namespace std;
- map <vector <int>, int> v2n;
- const int maxn = 405;
- int diff[maxn][maxn];
- int getN(vector <int> v)
- {
- if (v2n.count(v) == 0)
- {
- int sz = v2n.size();
- v2n[v] = sz;
- return sz;
- }
- return v2n[v];
- }
- int inB(int x, int l, int r)
- {
- return max(l, min(x, r) );
- }
- struct Square
- {
- int x1, x2, y1, y2;
- Square() : x1(), x2(), y1(), y2() {}
- Square(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
- Square(int x, int y, int l) : x1(x), y1(y), x2(x + l), y2(y + l) {}
- bool operator == (Square A)
- {
- return x1 == A.x1 && x2 == A.x2 && y1 == A.y1 && y2 == A.y2;
- }
- int operator - (Square A)
- {
- A.x1 -= x1;
- A.x2 -= x1;
- A.y1 -= y1;
- A.y2 -= y1;
- int n = x2 - x1;
- A.x1 = inB(A.x1, 0, n);
- A.x2 = inB(A.x2, 0, n);
- A.y1 = inB(A.y1, 0, n);
- A.y2 = inB(A.y2, 0, n);
- vector <int> v;
- if (A == Square(0, 0, n) )
- {
- printf("Empty\n");
- return getN(v);
- }
- v.push_back(n);
- if (A.x1 == A.x2 || A.y1 == A.y2)
- {
- printf("Square %d\n", n);
- return getN(v);
- }
- if (A.x1 == 0 && A.y1 == 0 && A.y2 == n)
- {
- A.x1 = n - A.x2;
- A.x2 = n;
- }
- if (A.y1 == 0 && A.x1 == 0 && A.x2 == n)
- {
- A.y1 = n - A.y2;
- A.y2 = n;
- }
- v.push_back(A.x1);
- v.push_back(A.x2);
- v.push_back(A.y1);
- v.push_back(A.y2);
- printf("n = %d, [%d .. %d] x [%d .. %d]\n", n, A.x1, A.x2, A.y1, A.y2);
- return getN(v);
- }
- void read()
- {
- int l;
- scanf("%d %d %d", &x1, &y1, &l);
- x2 = x1 + l;
- y2 = y1 + l;
- }
- };
- Square sq[maxn];
- int cnt[maxn * maxn];
- long long ans = 0;
- int main()
- {
- freopen("squares.in", "r", stdin);
- freopen("squares.out", "w", stdout);
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- {
- sq[i].read();
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- if (i == j)
- continue;
- printf("i = %d, j = %d\n", i, j);
- diff[i][j] = sq[i] - sq[j];
- ans += cnt[diff[i][j] ];
- cnt[diff[i][j] ]++;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- if (i == j)
- continue;
- int c = i;
- int d = j;
- for (int it = 0; it < 2; it++)
- {
- if (diff[i][j] == diff[c][d] )
- ans --;
- swap(c, d);
- }
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- for (int h = 0; h < n; h++)
- {
- if (i == j || i == h || j == h)
- continue;
- int a = i;
- int b = j;
- for (int it1 = 0; it1 < 2; it1++)
- {
- int c = i;
- int d = h;
- for (int it2 = 0; it2 < 2; it2++)
- {
- if (diff[a][b] == diff[c][d] )
- ans--;
- swap(c, d);
- }
- swap(a, b);
- }
- }
- printf("%I64d\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement