IP聚合
Accepts: 332
Submissions: 781
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
解题报告:
醉了,依然是模拟题,暴力法又不超时,好吧。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
int n;
#define maxn 1010
unsigned int input[maxn];
void Solve()
{
}
int main()
{
//freopen("input.txt", "r", stdin);
int times;
scanf("%d", ×);
for (int i = 1; i <= times; ++i)
{
printf("Case #%d:\n", i);
int N, M;
scanf("%d %d", &N, &M);
int a, b, c, d;
for (int j = 0; j < N; ++j)
{
scanf("%d.%d.%d.%d", &a, &b, &c, &d);
input[j] = (a << 8) + b;
input[j] <<= 8;
input[j] += c;
input[j] <<= 8;
input[j] += d;
}
for (int j = 0; j < M; ++j)
{
scanf("%d.%d.%d.%d", &a, &b, &c, &d);
unsigned int num = (a << 8) + b;
num <<= 8;
num += c;
num <<= 8;
num += d;
set<unsigned int> con;
for (int k = 0; k < N; ++k)
{
con.insert(num & input[k]);
}
printf("%d\n", con.size());
}
Solve();
}
return 0;
}