Content

有 \(n\) 个形如 \(a_i.b_i.c_i.d_i\) 的 IP 地址。有 \(m\) 条命令,每条命令由一条字符串 \(s\) 和一个形如 \(p.q.r.s\) 的 IP 地址,你需要输出这个命令,并输出这个命令所指向的 IP 地址对应的名称。

数据范围:\(1\leqslant n,m\leqslant 1000,0\leqslant a_i,b_i,c_i,d_i,p,q,r,s\leqslant 255,1\leqslant|s|\leqslant 10\)。

Solution

这题乍一看有些高大上,但看到这个数据范围之后,我就认定了这道题目只需要 \(\mathcal{O}(nm)\) 的枚举就能够解决。具体怎么解决?很简单,输入完每一次命令,直接再在所有 \(n\) 个 IP 地址中一个一个去找,看是否有和当前命令的 IP 地址相等的,一旦碰到相等的就直接输出就好了。

Code

string name[1007];
int n, m, a[1007], b[1007], c[1007], d[1007]; int main() {
getint(n), getint(m);
_for(i, 1, n) {cin >> name[i]; scanf("%d.%d.%d.%d", &a[i], &b[i], &c[i], &d[i]);}
_for(i, 1, m) {
string tmpname; int tmpa, tmpb, tmpc, tmpd;
cin >> tmpname;
scanf("%d.%d.%d.%d;", &tmpa, &tmpb, &tmpc, &tmpd);
_for(j, 1, n)
if(tmpa == a[j] && tmpb == b[j] && tmpc == c[j] && tmpd == d[j]) {
cout << tmpname << ' ';
writeint(tmpa), putchar('.');
writeint(tmpb), putchar('.');
writeint(tmpc), putchar('.');
writeint(tmpd), putchar(';'), putchar(' '), putchar('#');
cout << name[j] << endl;
break;
}
}
return 0;
}

CF918B Radio Station 题解的更多相关文章

  1. Radio Station

    B. Radio Station time limit per test:  2 seconds memory limit per test:  256 megabytes input: standa ...

  2. Codeforces Round #459 (Div. 2):B. Radio Station

    B. Radio Station time limit per test2 seconds memory limit per test256 megabytes Problem Dsecription ...

  3. 【Codeforces Round #459 (Div. 2) B】 Radio Station

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map模拟一下映射就好了. [代码] #include <bits/stdc++.h> using namespace ...

  4. 【23.48%】【codeforces 723C】Polycarp at the Radio

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  6. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

  7. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  8. Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

    C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. [LeetCode 题解]: Maximum Subarray

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Find the c ...

随机推荐

  1. 抽象类和接口的区别详解、package和import

    1.抽象类和接口以及抽象类和接口的区别. 1.1.抽象类的基础语法(见昨天笔记) 1.2.接口的基础语法 1.接口是一种"引用数据类型". 2.接口是完全抽象的. 3.接口怎么定义 ...

  2. 【JQuery】(1)JQuery基础

    JQuery基础 2019-11-02  21:11:17  by冲冲 1.jQuery简介 jQuery:轻量级."写的少,做的多".JavaScript函数库. 2.jQuer ...

  3. [SCOI2009] windy 数 (数位dp)

    题目 算法 应该是一道很经典的数位dp题 我们设dp[i][j]是填到第i位此时第i位的数是j的方案数 然后进行转移(代码注释) 代码 #include<iostream> #includ ...

  4. 洛谷 P3267 - [JLOI2016/SHOI2016]侦察守卫(树形 dp)

    洛谷题面传送门 经典题一道,下次就称这种"覆盖距离不超过 xxx 的树形 dp"为<侦察守卫模型> 我们考虑树形 \(dp\),设 \(f_{x,j}\) 表示钦定了 ...

  5. Codeforces Round #691 (Div. 2) 题解

    A 不多说了吧,直接扫一遍求出 \(r_i>b_i\) 的个数和 \(r_i<b_i\) 的个数 B 稍微打个表找个规律就可以发现,当 \(n\) 为奇数的时候,答案为 \(\dfrac{ ...

  6. 洛谷 P5406 - [THUPC2019]找树(FWT+矩阵树定理)

    题面传送门 首先看到这道题你必须要有一个很清楚的认识:这题新定义的 \(\oplus\) 符号非常奇怪,也没有什么性质而言,因此无法通过解决最优化问题的思路来解决这个问题,只好按照计数题的思路来解决, ...

  7. SUNTANS 及 FVCOM 对流扩散方程求解简介[TBC]

    最近接到一个任务,就是解决FVCOM中对流扩散计算不守衡问题.导师认为是其求解时候水平和垂向计算分开求解所导致的,目前我也没搞清到底有什么问题,反正就是让把SUNTANS的对流扩散计算挪到FVCOM中 ...

  8. 【R】clusterProfiler的GO/KEGG富集分析用法小结

    前言 关于clusterProfiler这个R包就不介绍了,网红教授宣传得很成功,功能也比较强大,主要是做GO和KEGG的功能富集及其可视化.简单总结下用法,以后用时可直接找来用. 首先考虑一个问题: ...

  9. 睡眠或者重启windows,无法ssh连接或者pingVMware的虚机

    睡眠后无法直接ssh重连VMware主机问题 这个问题我在win8上出现过,win10看了下同事可以正常连,不知道其他有没有问题. 解决方法: 1.关闭vmnet8和vmnet0里面的 npcap 功 ...

  10. No.1 R语言在生物信息中的应用——序列读取及格式化输出

    目的:读入序列文件(fasta格式),返回一个数据框,内容包括--存储ID.注释行(anno).长度(len).序列内容(content) 一.问题思考: 1. 如何识别注释行和序列内容行 2. 如何 ...