Pagini recente » Cod sursa (job #2542043) | Cod sursa (job #196040) | Cod sursa (job #2519941) | Cod sursa (job #334852) | Cod sursa (job #866504)
Cod sursa(job #866504)
#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
const int Base = 2;
const int NU = 2;
const int U[] = {666013, 1000003};
const int MaxN = 1005;
int M, A[MaxN], B[MaxN], C[MaxN];
int N, Index[MaxN], Hash[NU][MaxN], Regions;
inline int Side(const int L, const int x, const int y) {
return (A[L] * x + B[L] * y + C[L] >= 0 ? 1 : 0);
}
inline bool Equal(const int a, const int b) {
for (int h = 0; h < NU; ++h)
if (Hash[h][a] != Hash[h][b])
return false;
return true;
}
inline bool Compare(const int a, const int b) {
for (int h = 0; h < NU; ++h)
if (Hash[h][a] != Hash[h][b])
return Hash[h][a] < Hash[h][b];
return false;
}
void Solve() {
for (int i = 0; i < N; ++i) {
int x, y; assert(scanf("%d %d", &x, &y) == 2);
for (int h = 0; h < NU; ++h)
for (int j = 0; j < M; ++j)
Hash[h][i] = (Base * Hash[h][i] + Side(j, x, y)) % U[h];
}
for (int i = 0; i < N; ++i)
Index[i] = i;
sort(Index, Index + N, Compare);
Regions = 1;
for (int i = 1; i < N; ++i)
if (!Equal(Index[i - 1], Index[i]))
++Regions;
}
void Read() {
assert(freopen("regiuni.in", "r", stdin));
assert(scanf("%d %d", &M, &N) == 2);
for (int i = 0; i < M; ++i)
assert(scanf("%d %d %d", &A[i], &B[i], &C[i]) == 3);
}
void Print() {
assert(freopen("regiuni.out", "w", stdout));
printf("%d\n", Regions);
}
int main() {
Read();
Solve();
Print();
return 0;
}