IP聚合
Accepts: 1901
Submissions: 4980
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include <set> #include <map> #include <queue> #include <string> #define LL long long using namespace std; struct IP { int a, b, c, d; bool operator < (const IP x) const { if (a != x.a) return a < x.a; else if (b != x.b) return b < x.b; else if (c != x.c) return c < x.c; else if (d != x.d) return d < x.d; return false; } }; int n, m; IP f[1005], t; void Input() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d.%d.%d.%d", &f[i].a, &f[i].b, &f[i].c, &f[i].d); } void Work() { IP k; for (int i = 0; i < m; ++i) { set <IP> s; scanf("%d.%d.%d.%d", &t.a, &t.b, &t.c, &t.d); for (int j = 0; j < n; ++j) { k.a = f[j].a & t.a; k.b = f[j].b & t.b; k.c = f[j].c & t.c; k.d = f[j].d & t.d; s.insert(k); } printf("%d\n", s.size()); } } int main() { int T; scanf("%d", &T); for (int times = 1; times <= T; ++times) { Input(); printf("Case #%d:\n", times); Work(); } return 0; }