[CF959B]Mahmoud and Ehab and the message题解
超级大模拟
直接用map吧string对应到编号上来,然后在开个数组把每个编号对应到每个可以互相转化区块上来,预处理出区块的最小值,使用时直接取最小是即可
代码
#include <cstdio>
#include <iostream>
#include <map>
#define ll long long
#define min(a,b) ((a<b)?a:b)
using namespace std;
inline ll read(){
ll x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
map<string, int> mp;
string s[100005];
int a[100005];
int dy[100005];
int val[100005];
int main(){
int n = read(), k = read(), m = read();
for (int i = 1; i <= n; ++i)
cin >> s[i];
for (int i = 1; i <= n; ++i)
a[i] = read(), mp[s[i]] = i;
int q;
for (int i = 1; i <= k; ++i)
val[i] = 2147483647;
for (int i = 1; i <= k; ++i){
q = read();
for (int j = 0; j < q; ++j){
int t = read();
dy[t] = i, val[i] = min(val[i], a[t]);
}
}
string c; ll ans = 0;
for (int i = 1; i <= m; ++i){
cin >> c;
ans += val[dy[mp[c]]];
}
printf("%lld", ans);
return 0;
}
[CF959B]Mahmoud and Ehab and the message题解的更多相关文章
- Mahmoud and Ehab and the message
Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from ...
- [CF959E]Mahmoud and Ehab and the xor-MST题解
解法 又是一道结论题? 我的做法比较奇怪且没有证明 #include <cstdio> #include <cmath> #define ll long long int ma ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- [CF959A]Mahmoud and Ehab and the even-odd game题解
题意简述 一个数n,Mahmoud珂以取(即如果取\(k\),使\(n = n - k\))一个正偶数,Ehab珂以取一个正奇数,一个人如果不能取了(对于Mahmoud和Ehab \(n = 0\), ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- CF 862A Mahmoud and Ehab and the MEX【数组操作】
A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 megabytes in ...
- CF862B Mahmoud and Ehab and the bipartiteness 二分图染色判定
\(\color{#0066ff}{题目描述}\) 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 \(\color{#0066ff}{输入格式}\) The first line ...
- 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 ...
- 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 ...
随机推荐
- python 每周作业
day2:python的简介与认识day2:# 1.写一个登录程序# username# passwd# 让用户输入账号和密码,输入用户和密码输入正确的话# 提示你 xxx,欢迎登录,今天的日期是xx ...
- list、tuple、dict加*星号
*相当于解压的作用,当list中只有一个元素时,利用*作用相当于直接去[],去[]后的数据类型是字符串. _list = [1,2,3] _tuple = (1,2,3) _dict = {1:'a' ...
- Java Bean 使用包装类型 还是基本类型
参考:实体类中用基本类型好,还是用包装类型好_ - 牵牛花 - 博客园 int优缺点 优点: 1.用于Bean的时候,有默认值.比如自己拼接sql增加一个User时,会方便很多,不过现在都用ORM框架 ...
- 最长k可重线段集问题【费用流】【优先队列Dijkstra费用流】
题目链接 与最长K可重区间问题一样的解法,但是这道题却有很多需要注意的地方,譬如就是精度问题,一开始没考虑到sprt()里面的乘会爆了精度,然后交上去竟然是TLE,然后找的原因方向也没对,最后TLE了 ...
- 腾讯视频的手机端的地址和PC端的地址是不一样的
腾讯视频的手机端的地址和PC端的地址是不一样的,所以使用iframe的时候记得要使用手机端的地址
- 阻塞队列 BlockingQueue 常用方法详解
1.offer()和add()的区别 add()和offer()都是向队列中添加一个元素.但是如果想在一个满的队列中加入一个新元素,调用 add() 方法就会抛出一个 unchecked 异常,而调用 ...
- Git-第N篇碰见的一些问题
1.关于windows平台自动换行问题 warning: LF will be replaced by CRLF in readme.txt. The file will have its origi ...
- Runnable和Thread区别和比较
在很多博客中用这样一个例子来说明 Runnable更容易实现资源共享,能多个线程同时处理一个资源. 看代码: public static void main(String[] args) { new ...
- HDU 4013 Distinct Subtrees(树的最小表示)
Distinct Subtrees Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Other ...
- Python中yield和return两者之间区别
在任何函数都有返回值,一般都是想到return 关键词,在函数生成器中有个关键词 yield 也可以做返回值,在函数没调用之前,是不会输出任何东西的 1,return 用法 def stu(): re ...