CF499B Lecture 题解
Content
有一个教授用 \(\texttt{A}\) 语言讲课。你觉得他讲的太快了,所以决定使用 \(\texttt{A}\) 语言和 \(\texttt{B}\) 语言记笔记。
已知 \(\texttt{A}\) 语言和 \(\texttt{B}\) 语言中的 \(m\) 对单词的意思是互相对等的,因此,使用 \(\texttt{B}\) 语言可能会让你的笔记更加简洁。当然,如果 \(\texttt{A}\) 语言中的单词的长度和 \(\texttt{B}\) 语言中意思相等的单词的长度相等,甚至 \(\texttt{A}\) 语言中的单词长度还要短,那么你还是会首选用 \(\texttt{A}\) 语言记笔记。
现在给出教授的演讲(有 \(n\) 个单词),请你按照以上规则记好笔记。
数据范围:\(1\leqslant n,m\leqslant 3000\)。
Solution
我们为什么不使用 \(\texttt{map}\) 来解决这道题目呢?
由于可以肯定教授只用 \(\texttt{A}\) 语言来演讲,因此我们直接将 \(\texttt{A}\) 语言中的意思相等的单词用 \(\texttt{map}\) 映射到 \(\texttt{B}\) 语言中去,然后在每个单词对比是否会使记笔记的长度减少即可。
Code
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int n, m;
string a, b, sp[3007];
map<string, string> mm1;
int main() {
scanf("%d%d", &n, &m);
while(m--) {
cin >> a >> b;
mm1[a] = b;
}
for(int i = 1; i <= n; ++i) {
cin >> sp[i];
if(mm1[sp[i]].size() < sp[i].size()) sp[i] = mm1[sp[i]];
}
for(int i = 1; i <= n; ++i) cout << sp[i] << ' ';
}
CF499B Lecture 题解的更多相关文章
- [C2P3] Andrew Ng - Machine Learning
##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...
- Lecture Sleep(前缀和)
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai the ...
- Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]
传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- 【论文阅读】Beyond OCR + VQA: 将OCR融入TextVQA的执行流程中形成更鲁棒更准确的模型
论文题目:Beyond OCR + VQA: Involving OCR into the Flow for Robust and Accurate TextVQA 论文链接:https://dl.a ...
- appdata 文件夹
appdata file AppData 的位置在 c:\Users\{UserName}\Appdata ,它是从 Windows Vista 开始引入的,直至今天的 Windows 7, 8, 1 ...
- Jenkins系列-权限管理
在实际工作中,存在多个团队都需要Jenkins来实现持续交付,但是又希望不同团队之间进行隔离,每个项目有自己的view, 只能看到自己项目的jenkins job. 但是,jenkins默认的权限管理 ...
- R语言与医学统计图形-【15】ggplot2几何对象之线图
ggplot2绘图系统--几何对象之线图 曲线:点连线.路径曲线.时间序列曲线.模型拟合曲线...... 直线:水平直线.垂直直线.斜线. 1.曲线 对象及其参数. #路径图 geom_path(ma ...
- android Fragment跳转Fragment
android Fragment跳转Fragment,最新的android studio3 在系统模板建立的BottomNavigationView 中跳转方式 此版本下不能用FragmentMana ...
- 29-Regular Expression Matching-leetcode
'.' Matches any single character. '*' Matches zero or more of the preceding element. The matching sh ...
- C#gridview尾部统计
protected void gridSettlement_RowDataBound(object sender, GridViewRowEventArgs e) { if (dtSettlement ...
- Linux驱动实践:如何编写【 GPIO 】设备的驱动程序?
作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...
- A Child's History of England.43
PART THE SECOND When the King heard how Thomas à Becket had lost his life in Canterbury Cathedral, t ...
- day22面向对象编程思想
day22面向对象编程思想 1.面向过程 面向过程: 核心是"过程"二字 过程的终极奥义就是将程序流程化 过程是"流水线",用来分步骤解决问题的 面向对象: 核 ...