IP 집합

6193 단어 기타 경기
IP  
Accepts: 447
Submissions: 1135
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
    ,         ,         ,             ,        IP  ,                 ,        。            IP              ,  :
    :A.B.C.D
IP   :a.b.c.d
    :(A&a).(B&b).(C&c).(D&d)
Input
         TTT,(1≤T≤50)(1 \leq T \leq 50)(1≤T≤50)         ,
   TTT     。           ,
        N(1≤N≤1000,1≤M≤50),MN(1 \leq N \leq 1000, 1 \leq M \leq 50),MN(1≤N≤1000,1≤M≤50),M。   NNN ,       ,     IP   ,
    MMM ,             。IP            A.B.C.DA.B.C.DA.B.C.D   ,  A,B,C,DA,B,C,DA,B,C,D      ,     255。
Output
        ,    :
     : "Case #i:" 。iii   iii     。
            ,               ,                 。
Sample Input
Copy
2
5 2
192.168.1.0
192.168.1.101
192.168.2.5
192.168.2.7
202.14.27.235
255.255.255.0
255.255.0.0
4 2
127.127.0.1
10.134.52.0
127.0.10.1
10.134.0.2
235.235.0.0
1.57.16.0
Sample Output
Copy
Case #1:
3
2
Case #2:
3
4
Statistic | Submit | Clarifications | Back
#include 
#include 
#include 
#include 
#define MAXN 1050
typedef struct{int a,b,c,d;} ip;  /// ip
typedef struct{int A,B,C,D;} zw;  ///     
typedef struct{int a,b,c,d;} recall;
ip IP[MAXN];zw ZW[MAXN];recall RECALL[MAXN];
int Count;
int cmp(const void *a,const void *b)  ///    
{
    recall A  = *(recall *)a;recall B  = *(recall *)b;
    if(A.a!=B.a) return A.a - B.a;
    if(A.b!=B.b) return A.b - B.b;
    if(A.c!=B.c) return A.c - B.c;
    return A.d - B.d;
}
bool  CMP (int i,int j)
{
    int flag = 1;
    if(RECALL[i].a != RECALL[j].a ) flag = 0;
    if(RECALL[i].b != RECALL[j].b ) flag = 0;
    if(RECALL[i].c != RECALL[j].c ) flag = 0;
    if(RECALL[i].d != RECALL[j].d ) flag = 0;
    return flag;
}
int Cal(void)
{
    int ans = 0;
    for(int i=1,j=2;i<=Count;)
    {
        ans++;
        while(CMP(i,j)&&j<=Count) j++;
        i=j;j++;
    }
    return ans;
}
void Handle(int n,int m)
{
    for(int i=1;i<=n;i++) scanf("%d%*c%d%*c%d%*c%d",&IP[i].a,&IP[i].b,&IP[i].c,&IP[i].d);
    for(int i=1;i<=m;i++) scanf("%d%*c%d%*c%d%*c%d",&ZW[i].A,&ZW[i].B,&ZW[i].C,&ZW[i].D);
    for(int j=1;j<=m;j++)
    {
        Count = 0;
        for(int i=1;i<=n;i++)
        {
            RECALL[++Count].a =  ZW[j].A&IP[i].a;
            RECALL[Count].b =  ZW[j].B&IP[i].b;
            RECALL[Count].c =  ZW[j].C&IP[i].c;
            RECALL[Count].d =  ZW[j].D&IP[i].d;
        }
        qsort(RECALL+1,Count,sizeof(RECALL[0]),cmp);
        printf("%d
"
,Cal()); } } int main(void) { // freopen("D:\\test.txt","r",stdin); // freopen("D:\\tsst.txt","w",stdout); int T;scanf("%d",&T); for(int i=1,N,M;i<=T&&(scanf("%d %d",&N,&M));i++) {printf("Case #%d:
"
,i);Handle(N,M);} }

좋은 웹페이지 즐겨찾기