模拟 百度之星资格赛 1003 IP聚合
/*
模拟水题,排序后找出重复的ip就可以了
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
struct Ip
{
int a, b, c, d;
}ip[MAXN];
struct H
{
int a, b, c, d;
}h[MAXN];
int ans[]; bool cmp(H x, H y)
{
if (x.a == y.a)
{
if (x.b == y.b)
{
if (x.c == y.c) return x.d < y.d;
else return x.c < y.c;
}
else return x.b < y.b;
}
else return x.a < y.a;
} int main(void) //百度之星资格赛 1003 IP聚合
{
int t, cas = ;
scanf ("%d", &t);
while (t--)
{
int n, m; scanf ("%d%d", &n, &m);
for (int i=; i<=n; ++i)
scanf ("%d.%d.%d.%d", &ip[i].a, &ip[i].b, &ip[i].c, &ip[i].d); memset (ans, , sizeof (ans));
for (int i=; i<=m; ++i)
{
int u, v, w, x;
scanf ("%d.%d.%d.%d", &u, &v, &w, &x);
for (int j=; j<=n; ++j)
{
h[j].a = (ip[j].a & u); h[j].b = (ip[j].b & v);
h[j].c = (ip[j].c & w); h[j].d = (ip[j].d & x);
} sort (h+, h++n, cmp); int cnt = ;
for (int k=; k<=n; ++k)
{
if (h[k].a == h[k-].a &&
h[k].b == h[k-].b &&
h[k].c == h[k-].c &&
h[k].d == h[k-].d) cnt++;
} ans[i] = (n - cnt);
} printf ("Case #%d:\n", ++cas);
for (int i=; i<=m; ++i) printf ("%d\n", ans[i]);
} return ;
} /*
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
*/
模拟 百度之星资格赛 1003 IP聚合的更多相关文章
- 模拟 2015百度之星资格赛 1003 IP聚合
题目传送门 /* 模拟水题,排序后找出重复的ip就可以了 */ #include <cstdio> #include <iostream> #include <algor ...
- ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)
Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...
- [百度之星]资格赛:IP聚合
保持着也不知道什么情怀,觉得到现在才能发出来.这道题做完之后看了其他人的代码,然后再看我的,不得不说,真是幼稚的很,尤其是输入这一块,都什么跟什么啊. 但相较于之前来说,不像以前慌张了,学会先思考再去 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- ip聚合(百度之星资格赛1003)
IP聚合 点击这里 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下, ...
- 百度之星资格赛 1003 度度熊与邪恶大魔王(二维dp)
分析 挺好的一道题 dp[i][j]表示打败i颗血j防御力的怪兽需要的最少宝石数 然后就好了,复杂度\(O(n+m*1000*10)\) #include <bits/stdc++.h> ...
- 百度之星 资格赛 1003 度度熊与邪恶大魔王 dp(背包)
度度熊与邪恶大魔王 Accepts: 1141 Submissions: 6840 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...
- 2016百度之星 资格赛ABCDE
看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...
- HDU 5688:2016"百度之星" - 资格赛 Problem D
原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- configuration默认设置
所以 上面的configuration的set可以省略,但是也可以自己改变设置,如下所示:
- 创建Material Design风格的Android应用--应用主题
本人全部文章首先公布于个人博客,欢迎关注,地址:http://blog.isming.me 昨天正式公布了android 5,同一时候android developer站点也更新了,添加了创建Mate ...
- bzoj4169: Lmc的游戏
终于有道我会的了... int f[2][maxn],g[2][maxn],tot[maxn];//构造叶子编号时希望最大/小result 先手取子树最小/大的编号的排名 tot是子树中叶子个数 如果 ...
- linux防火墙过滤规则
一.linux防火墙基础 防火墙分为硬件防火墙和软件防火墙. 1.概述 linux 防火墙体系主要工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙. 包过滤机制:netfil ...
- codeforces 414B B. Mashmokh and ACM(dp)
题目链接: B. Mashmokh and ACM time limit per test 1 second memory limit per test 256 megabytes input sta ...
- MFC显示Mat图片
Opencv在1.0时代,在MFC框架上显示图片可以通过Cvvimage类里的DrawPicToHDC( IplImage *img, UINT ID)方法方便的显示出来,当然当时使用的还是IpIIm ...
- I.MX6 新版、旧版u-boot不兼容问题
/************************************************************************* * I.MX6 新版.旧版u-boot不兼容问题 ...
- SPOJ:Ada and Orange Tree (LCA+Bitset)
Ada the Ladybug lives near an orange tree. Instead of reading books, she investigates the oranges. T ...
- Codeforces-914F Substrings in a String (Bitset求T串中S串出现次数)
之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c, ...
- iOS中键盘的收起
在UIViewController中收起键盘,除了调用相应控件的resignFirstResponder方法之外,还有另外三种方法: 重载UIViewController中的touchesBegin方 ...