# UVALive 7043 International Collegiate Routing Contest（字典树）

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int N=3*1e4+10;
int T,cas=1;
int n,ansn;
unsigned int a[N],len[N],ans[N<<1],al[N<<1];

const int maxc=2;
int ch[N<<5][maxc],si[N<<5],size;
void init()
{
memset(ch[1],0,sizeof(ch[1]));
si[1]=0;
size=2;
ansn=0;
}
void insert(int s,int BIT)
{
if(BIT==0)
{
si[1]=1;
return;
}
int u=1;
for(int i=31;i>31-BIT;i--)
{
int c=(s&(1<<i)?1:0);
if(!ch[u][c])
{
memset(ch[size],0,sizeof(ch[0]));
si[size]=0;
ch[u][c]=size++;
}
u=ch[u][c];
}
si[u]=1;
}
void dfs(int u,unsigned int sum,int depth)
{
if(si[u]) return;
if(!ch[u][0]&&!ch[u][1])
{
ans[ansn]=sum;
al[ansn++]=depth;
return;
}
if(ch[u][0]) dfs(ch[u][0],sum,depth+1);
else
{
ans[ansn]=sum;
al[ansn++]=depth+1;
}
if(ch[u][1]) dfs(ch[u][1],sum|(1U<<(31-depth)),depth+1);
else
{
ans[ansn]=sum|(1U<<(31-depth));
al[ansn++]=depth+1;
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&T);
while(T--)
{
init();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
a[i]=0;
for(int j=0,x;j<4;j++)
{
scanf("%d%*c",&x);
//printf("%d ",x);
a[i]=a[i]<<8|x;
}
scanf("%d",len+i);
//printf("%d\n",len[i]);
insert(a[i],len[i]);
}
dfs(1,0,0);
printf("Case #%d:\n",cas++);
printf("%d\n",ansn);
for(int i=0;i<ansn;i++)
{
int b[4];
for(int j=3;j>=0;j--)
{
ans[i]>>=8;
}
printf("%d.%d.%d.%d/%d\n",b[0],b[1],b[2],b[3],al[i]);
}
}
return 0;
}


#### UVALive - 7043-International Collegiate Routing Contest

2017-10-13 18:53:20

#### 2014 ACM/ICPC Xi'an Regional I - International Collegiate Routing Contest

2016-08-16 10:57:50

#### UVALive 7043 International Collegiate Routing Contest 字典树

2015-09-03 21:15:41

#### ACM Amman Collegiate Programming Contest C. Street Lamps

2017-06-04 11:12:58

#### UVALive 7043 International Collegiate Routing Contest 字典树，递归

2017-03-08 10:51:42

#### 2017 ACM Amman Collegiate Programming Contest

2017-08-26 23:24:18

#### 2015 Syrian Private Universities Collegiate Programming Contest（gym101020）

2016-06-23 00:13:41

#### 2013年成都acm题目

2013年11月02日 299KB 下载

#### 2015 ACM Arabella Collegiate Programming Contest（F题）

2015-05-04 14:12:10

#### 杭州2013题目

2013年11月02日 848KB 下载