M - Violet Snow

Gym - 101350M

Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not have been the same every year. Therefore, after every trip, he always has leftover money in the currency of the country he visited.

Now he wants to see how much Jordanian Dinars he has after all those competitions. Can you help him convert the leftover money from all competitions to Jordanian Dinar, if that makes any cents?

Input

The first line of input is T – the number of test cases.

The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively.

The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Vi of that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive.

The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”).

Output

For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits.

Example

Input
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
Output
12.451000
https://blog.csdn.net/sevenjoin/article/details/81943864 自动建立key - value的对应。key 和 value可以是任意你需要的类型。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include <stdio.h>
#include <string.h>
#include <map>
//#define PI 3.1415926
using namespace std;
const double PI = acos(-1.0); int main()
{
int n ;
scanf("%d" , &n);
while(n--)
{
map<string , double>ma;
int m , p ;
scanf("%d%d" , &m ,&p);
for(int i = ; i < m ; i++)
{
string a ;
double b ;
cin >> a ;
scanf("%lf" , &b);
//map容器的三种插入,第一种key可以覆盖 ,其他两种不可以
ma[a] = b;
ma.insert(map<string , double>::value_type(a , b));
ma.insert(pair<string , double>(a , b));
}
double sum = ;
for(int i = ; i < p ; i++)
{
string a ;
double b;
scanf("%lf" , &b);
cin >> a;
if(a == "JD")
sum += b ;
else
sum += ma[a] * b ;
}
printf("%.6lf\n" , sum);
} return ;
}

应该没几个人用字典树吧

字典树是完全可行的,我就是因为没对用过的树初始化所有就wa了,

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include <stdio.h>
#include <string.h>
using namespace std;
int tree[][];
int k = ;
double vis[] ;
double sum = ;
void winsert(char *a , double val)
{
int len = strlen(a);
int p = ;
for(int i = ; i < len ; i++)
{
int c = a[i] - 'A';
if(!tree[p][c])
tree[p][c] = ++k ;
p = tree[p][c];
}
vis[p] = val ;
} double wsearch(char *a)
{
int p = ;
int len = strlen(a);
for(int i = ; i < len ; i++)
{
int c = a[i] - 'A';
if(!tree[p][c]) return ;
p = tree[p][c];
}
if(vis[p])
return vis[p];
} int main()
{
int n ;
scanf("%d" , &n);
while(n--)
{
k = ;
memset(vis, , sizeof(vis));
memset(tree , , sizeof(tree));
sum = ;
int m , p ;
scanf("%d%d" , &m ,&p);
// cout << m << " " << p << endl ;
char s[];
double val ;
for(int i = ; i < m ; i++)
{
scanf("%s%lf" ,s , &val);
winsert(s , val);
}
for(int i = ; i < p ; i++)
{
scanf("%lf%s" , &val , s);
sum += val * wsearch(s);
}
printf("%.6lf\n" , sum); } return ;
}

stl应用(map)或字典树(有点东西)的更多相关文章

  1. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...

  2. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  3. 51nod 1095 Anigram单词【hash/map/排序/字典树】

    1095 Anigram单词 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b ...

  4. STL中map与hash_map容器的选择收藏

    这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ...

  5. STL中map与hash_map的比较

    1. map : C++的STL中map是使用树来做查找算法; 时间复杂度:O(log2N) 2. hash_map : 使用hash表来排列配对,hash表是使用关键字来计算表位置; 时间复杂度:O ...

  6. poj2513--并查集+欧拉路+字典树

    经典好题,自己不知道哪里错了交上去是RE,可能是数组开的不好吧,字典树老碰到这种问题.. 先马上别人的代码,有空对拍看看 #include <cstdio> #include <cs ...

  7. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  8. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

  9. 洛谷 P3370 【模板】字符串哈希 (set||map||哈希||字典树(mle)

    P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. #友情提醒:如果真的想好 ...

随机推荐

  1. nextSibling 属性与 nextElementSibling 属性的异同

    不同点: nextSibling 属性返回元素节点之后的下一个兄弟节点(包括文本节点.注释节点): nextElementSibling 属性只返回元素节点之后的下一个兄弟元素节点(不包括文本节点.注 ...

  2. mssql 取数据指定条数(例:100-200条的数据)

    方法1:临时表 * into #aa from table order by time-- 将top m笔插入 临时表 select * from #aa order by time desc --d ...

  3. 微信小程序request(ajax)接口请求封装

    微信小程序request(ajax)接口请求封装 最近在进行小程序的编写,需要调用后端接口,经常要用到wx.request方法,所以就自己封装了一下,简化一下代码,如果能给大家提供帮助更好,在封装的时 ...

  4. python去除字符串中间空格的方法

    1.使用字符串函数replace a = 'hello world' a.replace(' ', '') # 'helloworld' 2.使用字符串函数split a = ''.join(a.sp ...

  5. C++ 编译器的安装(MinGW)

    GNU GNU是一个自由软件工程项目,GNU工程已经开发了一个被称为“GNU”(GNU是“不是UNIX”的缩写)的.对Unix向上兼容的完整的自由软件系统(free software system). ...

  6. Linux性能优化从入门到实战:09 内存篇:Buffer和Cache

      Buffer 是缓冲区,而 Cache 是缓存,两者都是数据在内存中的临时存储.   避免跟文中的"缓存"一词混淆,而文中的"缓存",则通指内存中的临时存储 ...

  7. java类实现序列化的方法?collection框架中实现什么样的接口

  8. HashMap测试程序1

    package com.iotek.map; import java.util.Collection;import java.util.HashMap;import java.util.Map;imp ...

  9. action function

    Action委托具有Action<T>.Action<T1,T2>.Action<T1,T2,T3>……Action<T1,……T16>多达16个的重载 ...

  10. ORACLE数据库 memory_target SGA 大小

    修改 memory_target 用oracle用户登录,sqlplus "/as sysdba"SQL> show parameters target;     show ...