模拟 百度之星资格赛 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) ...
随机推荐
- 【php】读取"文件列表"按时间倒序显示,并递归显示各层文件夹、!
思路: 1.读取该php所在文件夹的文件列表,用"改动时间.文件名称"做键值对,塞入数组.对"改动时间"倒序.(貌似不能直接按时间倒序读取文件列表,此处为间接方 ...
- Array types are now written with the brackets around the element type问题的解决方法
在xcode6.1中来编写swift空数组时.出现的的这个问题,依照官方 Swift 教程<The Swift Programming Language>来写 let emptyArray ...
- 智能停车O2O 独角兽初现:“ETCP停车”获5000万美金A轮融资
日前,国内第一智能停车平台"ETCP停车"宣布完毕A轮融资,由源代码资本.SIG.易车网.经纬中国和商企界知名人士联合投资超过5000万美金.同一时候获悉,ETCP作为中国 ...
- add time to file name
add time to file name echo 123 > $(date +"%Y%m%d_%H%M%S").now; mv /mnt/mongodb_data/dat ...
- TCP客户服务端
创建TCP服务端1.创建一个ServerSocket对象.2.调用accept()方法接收客户端请求.3.从Socket中获取I/O流.4.对I/O流进行读写操作,完成与客户端的交互.5.关闭I/O流 ...
- django rest_framework swagger使用案例
环境准备 环境要求: python3 django2 pip3 模块安装: pip3 install django-rest-framework pip3 install django-rest-sw ...
- POJ3045 Cow Acrobats —— 思维证明
题目链接:http://poj.org/problem?id=3045 Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- Java 字符串比较小知识
使用 String.compareTo 方法: compareTo() 的返回值是int, 它是先比较对应字符的大小(ASCII码顺序). 1.如果字符串相等,返回值0. 2.如果第一个字符和参数的第 ...
- 666 专题三 KMP & 扩展KMP & Manacher
KMP: Problem A.Number Sequence d.求子串首次出现在主串中的位置 s. c. #include<iostream> #include<stdio.h&g ...
- NSError分析
在iOS开发中,NSError的使用非常常见,使用也比较简单,也正因为简单,所以对这一部分知识不甚注重.但是近期在做app底层网络封装时发现了一些问题.我使用的网络框架是AFNetworking,AF ...