Mahmoud and Ehab and the message
Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the i-th word can be sent with cost ai. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?
The cost of sending the message is the sum of the costs of sending every word in it.
The first line of input contains integers n, k and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains n strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.
The third line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) where ai is the cost of sending the i-th word.
The next k lines describe the groups of words of same meaning. The next k lines each start with an integer x (1 ≤ x ≤ n) which means that there are x words in this group, followed by x integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.
The next line contains m space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.
The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.
5 4 4
i loser am the second
100 1 1 5 10
1 1
1 3
2 2 5
1 4
i am the second
107
5 4 4
i loser am the second
100 20 1 5 10
1 1
1 3
2 2 5
1 4
i am the second
116
In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116.
阅读理解题
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
//#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = ;
const long long inf = 0x7f7f7f7f7f7f7f7f;
const int INT = 0x3f3f3f3f;
int main()
{
int n, k, m;
cin >> n >> k >> m;
vector<string> s(n + );
map<string, int> mp;
map<int, int> mpn;
for (int i = ; i <= n; i++)
{
cin >> s[i];
mp[s[i]] = i;
}
for (int i = ; i <= n; i++)
{
int t;
cin >> t;
mpn[i] = t;
}
for (int i = ; i < k; i++)
{
int all,minn=INT;
cin >> all;
vector<int> v(all);
for(int i=;i<all;i++)
{
cin >> v[i];
minn = min(minn, mpn[v[i]]);
}
for (int i = ; i < all; i++)
{
mpn[v[i]] = minn;
}
}
ll res=;
while (m--)
{
string ss;
cin >> ss;
res += mpn[mp[ss]];
}
cout << res;
return ;
}
Mahmoud and Ehab and the message的更多相关文章
- [CF959B]Mahmoud and Ehab and the message题解
超级大模拟 直接用map吧string对应到编号上来,然后在开个数组把每个编号对应到每个可以互相转化区块上来,预处理出区块的最小值,使用时直接取最小是即可 代码 #include <cstdio ...
- Codeforces 862A Mahmoud and Ehab and the MEX
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- E - Mahmoud and Ehab and the bipartiteness CodeForces - 862B (dfs黑白染色)
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipa ...
- Codeforces 862B - Mahmoud and Ehab and the bipartiteness
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- CF 959 E. Mahmoud and Ehab and the xor-MST
E. Mahmoud and Ehab and the xor-MST https://codeforces.com/contest/959/problem/E 分析: 每个点x应该和x ^ lowb ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
随机推荐
- 为什么我用Ipad Pro做电子笔记和看PDF电子书
为什么我用Ipad Pro做电子笔记和看PDF电子书 Ipad做笔记的优点: 1.ipad整理的笔记可以随时修改,可以看PDF的书,2.纸质书很重携带不便3.ipad的可通过关键词搜索笔记内容 4.笔 ...
- [Contract] Solidity 判断 mapping 值的存在
比如 mapping(address => uint) tester,只需要判断 mapping 是否为默认值 0, tester[msg.sender] == 0 "You can ...
- MySQL 8 复制
MySQL 8.0 支持的复制方法: 传统方法(基于二进制日志文件位置) 新方法(基于GTID) MySQL 8.0 支持的同步类型: 异步复制(内置) 同步复制(NDB集群) 半同步复制(半同步复制 ...
- 无人机通信协议MAVLink简介
MAVLink MAVLink(Micro Air Vehicle Link,微型空中飞行器链路通讯协议)是无人飞行器与地面站(Ground Control Station ,GCS)之间通讯,以及无 ...
- C++->10.3.6.设有两个按升序排列的二进制文件a和b,将他们合并成一个新的升序二进制数据文件file。
#include<iostream.h> #include<stdlib.h> #include<string.h> #include<fstream.h&g ...
- tensor的维度扩张的手段--Broadcasting
broadcasting是tensorflow中tensor维度扩张的最常用的手段,指对某一个维度上重复N多次,虽然它呈现数据已被扩张,但不会复制数据. 可以这样理解,对 [b,784]@[784,1 ...
- LeetCode 704. 二分查找
题目链接:https://leetcode-cn.com/problems/binary-search/ 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函 ...
- asp.net core 自定义基于 HttpContext 的 Serilog Enricher
asp.net core 自定义基于 HttpContext 的 Serilog Enricher Intro 通过 HttpContext 我们可以拿到很多有用的信息,比如 Path/QuerySt ...
- PHP正则表达式及表单注册案例
正则表达式是一种具有特定模式的用来匹配文本的字符串 preg_match 匹配 $pattern = '/php/'; $subject = "php 是最好的编程语言,php 没有之一!& ...
- sift代码实现详解
1.创建高斯金字塔第-1组 1.1.将源图片转成灰度图 void ConvertToGray(const Mat& src, Mat& dst) { cv::Size size = s ...