mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1003.cpp
This commit is contained in:
parent
9e293e33f5
commit
bd492ba66a
61
BestCoder/AStar-PRE/1003.cpp
Normal file
61
BestCoder/AStar-PRE/1003.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
/// std::cin and std::cout is so slow.
|
||||
struct ippack
|
||||
{
|
||||
int a,b,c,d;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
for(int tt=1;tt<=t;tt++)
|
||||
{
|
||||
printf("Case #%d:\n",tt);
|
||||
vector<ippack> ip;
|
||||
int n,m;
|
||||
scanf("%d %d",&n,&m);
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
ippack s;
|
||||
scanf("%d.%d.%d.%d",&s.a,&s.b,&s.c,&s.d);
|
||||
ip.push_back(s);
|
||||
}
|
||||
for(int i=0;i<m;i++)
|
||||
{
|
||||
vector<unsigned long> ans;
|
||||
ippack s;
|
||||
scanf("%d.%d.%d.%d",&s.a,&s.b,&s.c,&s.d);
|
||||
for(int j=0;j<n;j++)
|
||||
{
|
||||
ippack k=ip.at(j);
|
||||
k.a&=s.a;
|
||||
k.b&=s.b;
|
||||
k.c&=s.c;
|
||||
k.d&=s.d;
|
||||
unsigned long tmp=(k.a<<24)|(k.b<<16)|(k.c<<8)|(k.d);
|
||||
int sz=ans.size();
|
||||
bool flag_isfound=false;
|
||||
for(int k=0;k<sz;k++)
|
||||
{
|
||||
if(ans.at(k)==tmp)
|
||||
{
|
||||
flag_isfound=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag_isfound)
|
||||
{
|
||||
ans.push_back(tmp);
|
||||
}
|
||||
}
|
||||
printf("%d\n",ans.size());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user