模拟 百度之星资格赛 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) ...
随机推荐
- [网页游戏开发]容器的使用及自定义Tab,RadioGroup,List,ViewStack
Morn里面,容器和其他普通组件不同,无需皮肤,所以也不能从组件树种拖动创建(Tab,RadioGroup例外),只能转换而来 Morn的容器组件主要有Box,Container,Panel,Tab, ...
- LeetCode 226 Invert Binary Tree(转换二叉树)
翻译 将下图中上面的二叉树转换为以下的形式.详细为每一个左孩子节点和右孩子节点互换位置. 原文 如上图 分析 每次关于树的题目出错都在于边界条件上--所以这次细致多想了一遍: void swapNod ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo DP+矩阵快速幂加速
E. Okabe and El Psy Kongroo Okabe likes to take walks but knows that spies from the Organization ...
- debian old version cd and distribution archives
1 debian old version cd/dvd 官网的old version image,下载速度很慢 http://cdimage.debian.org/cdimage 下面这个靠谱,是镜像 ...
- top load average
负载均值 等待运行的进程数
- Struts%$#区别
1.#符号的用途一般有三种.1)访问非根对象属性,例如示例中的#session.msg表达式,由于Struts 2中值栈被视为根对象,所以访问其他非根对象时,需要加#前缀.实际上,#相当于Action ...
- mysql无法远程访问
最近使用Navicat for MySQl访问远程mysql数据库,出现报错, 显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to ...
- 织梦CMS首页、列表页文章如何调出该文章TAG标签?
1.如果是dedecms v5.7版本直接使用标签 [field:id function=GetTags(@me)/] 就可以调用出来了.只不过不带连接的. 2.如果需要连接请注释掉include/h ...
- iOS NSString拼接字符串
NSString* str_C; // 结果字符串NSString* str_A, str_B; //已存在的字符串,需要将str_A和str_B连接起来 //方法1 str_C = [NSStrin ...
- java中匹配中文的正则表达式
java中要匹配中文的正则表达式可以有两种写法:一是使用unicode中文码:二是直接使用汉字字符: 例: (1)String str = "晴"; String regexStr ...