You may know that Bluegao University (formly Bluey University) is famous of networking technology. One day, their headmaster Yuege received a special router, along with a task about routing table.
In this problem, routing table is a (probably) big table with several items, each item represents a subnet. The router has limited function, it can only deal with two next-hops and one main routing table. Packets will be send to next hop A if there exists a subnet containing the destination of the packet in the main outing table. Otherwise they will be send to next hop B.
You may know that, IPv4 uses 32-bit (four-byte) addresses, which limits the address space to 4294967296 (232) addresses. IPv4 addresses may be written in any notation expressing a 32-bit integer value, for human convenience, they are most often written in the dot-decimal notation, which consists of four octets of the address expressed individually in decimal and separated by periods. But their binary notation is also very useful. For example, IP address 126.96.36.199 can be expressed in dot-binary notation as 10000000.00000010.10001110.00010111. A subnet is a block of adjacent IP addresses with exactly same binary prefix, and usually written as the first IP address in its address space together with the bit length of prefix, like “188.8.131.52/24”. If an IP address is in the range of an subnet, we say that this subnet contains the IP address.
Yuege’s task is to invert the behaviour of his router, make all packets currently routed to hop A route to hop B, and vice versa. Also he wants to keep the size of the main routing table as small as possible, for performance.
In short, for a given routing table (i.e. a bunch of subnets), we need to get its “complement”, i.e. calculate a minimum set of subnets which have no intersection with given subnets, and their union must be the whole IPv4 address space.
Remember that Bluegao University is famous of networking tech, as headmaster of Bluegao University, Yuege definitely knows how to solve such problem, but he is too lazy to code, so he turns to you for help.
The first line of the input gives the number of test cases,
For each test case, the first line contains an integer
Note that even if
/32’ part should not be omitted. And if
For each test case, first output one line ‘
Case #x:’, where
3 0 1 0.0.0.0/1 1 184.108.40.206/1
Case #1: 1 0.0.0.0/0 Case #2: 1 220.127.116.11/1 Case #3: 1 0.0.0.0/1
a, b, c, d 可转化为一个32-bit的0-1串，然后截取其中的前（高）
按照这些0-1串构造字符集大小为2的字典树(0-1 Trie Tree)。