IP聚合
来源:互联网 发布:暗黑破坏神2 mac 双开 编辑:程序博客网 时间:2024/06/06 12:47
子网掩码: A.B.C.D
IP地址:a.b.c.d
网络地址:(A&a).(B&b).(C&c).(D&d)
问在固定的子网掩码下有多少个网络地址。
#include <cstdio>#include <set>using namespace std;struct rec{ int a, b, c, d; bool operator <(const rec &s) const { if (this->a == s.a && this->b == s.b && this->c == s.c) return this->d < s.d; else if (this->a == s.a && this->b == s.b) return this->c < s.c; else if (this->a == s.a) return this->b < s.b; else return this->a < s.a; }};set<rec> s;const int MAXN = 1000;const int MAXM = 50;rec ip[MAXN];rec sm[MAXM];int main(){ int t; scanf("%d", &t); for (int i = 1; i <= t; i++) { printf("Case #%d:\n", i); int n, m; scanf("%d%d", &n, &m); for (int j = 0; j < n; j++) { scanf("%d.%d.%d.%d", &ip[j].a, &ip[j].b, &ip[j].c, &ip[j].d); } for (int j = 0; j < m; j++) { scanf("%d.%d.%d.%d", &sm[j].a, &sm[j].b, &sm[j].c, &sm[j].d); } for (int j = 0; j < m; j++) { for (int k = 0; k < n; k++) { rec tmp; tmp.a = sm[j].a & ip[k].a; tmp.b = sm[j].b & ip[k].b; tmp.c = sm[j].c & ip[k].c; tmp.d = sm[j].d & ip[k].d; s.insert(tmp); } printf("%lu\n", s.size()); s.clear(); } } return 0;}
0 0
- IP聚合
- IP聚合
- IP聚合
- IP聚合
- 1003—IP聚合
- IP地址聚合
- Elasticsearch聚合 之 Ip Range IP地址范围聚合
- 1003 IP聚合(模拟)
- 百度之星资格赛--IP聚合
- 百度程序设计大赛1003IP聚合
- 【百度之星】1003 IP聚合
- 百度之星资格赛2015IP聚合
- [百度之星]资格赛:IP聚合
- 谋财害命之星热身赛1003IP聚合
- 【2015百度之星】 IP聚合
- 2015百度之星之-IP聚合
- 百度之星2015资格赛 IP聚合
- bestcoder 百度之星 1003 IP聚合
- [SCOI2016][BZOJ4569]萌萌哒
- 关于两个"集合"相同的判断
- LINUX 中的一些配置文件
- tcp回射服务器程序处理僵死进程
- C++ 声明和定义
- IP聚合
- 动手制作操作系统——启动区制作
- ==与equals方法的区别
- C++第5次作业
- HDU 2571 命运(简单DP)
- Linux内核同步方法
- 剑指offer剖析__空格替换字符串问题
- in与exist , not in与not exist 的区别
- MVC3中Html.BeginForm与Ajax.BeginForm