题目挺长,但是说的挺清楚,最后还直接给出了算法,直接按照给出的算法就能得出答案
我们只需要处理输入和输出,将格式转化为自己熟悉的格式方便接下来的处理即可
这次的第三题对时间卡的挺紧,在同级合并那里我用了链表优化,不然会超时
还有一开始我用string保存ip,结果最后一组数据过不去
之后改用了整型保存,再用特定的方法处理,比string快很多
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1e6+10;
long long P[34]; //倒着保存2的幂次
struct IP
{
ll s;
int len;
bool operator < (const IP &u) const
{
if(s<u.s) return true;
if(s>u.s) return false;
return len<u.len;
}
}ip[N];
bool ziji(IP a,IP b) //查询b是不是a的子集
{
if(a.len>b.len) return false;
if(a.s/P[a.len+1]!=b.s/P[a.len+1]) return false;
return true;
}
int l[N];
string ans[N];
int main()
{
P[33]=1;
for(int i=32;i>=0;i--)
P[i