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. 使用Nginx代理和转发Websocket连接

    1.Websocket 简介 WebSocket协议是基于TCP的一种新的网络协议.它实现了浏览器与服务器全双工(full-duplex)通信——允许服务器主动发送信息给客户端. 2.Nginx 简介 ...

  2. CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境

    ---恢复内容开始--- 一.系统环境 系统平台:CentOS 6.5 (Final) Apache版本:httpd-2.2.31.tar.gz(最新版本2015-07-16) Mysql 版本:my ...

  3. springMvc几个常用注解

    浏览器本省就是get ,post 可以用form表单 @RequestMapping: 作用:用来映射请求的url @RequestMapping注解的多个属性是与(且)的关系,必须同时满足 位置:可 ...

  4. KC705E 增强版 基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡

    KC705E 增强版 基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡 一.板卡概述 本板卡基于Xilinx公司的FPGAXC7K325T-2FF ...

  5. hdu 5963:朋友

    刚看到这题时感觉是树上博弈,然后我开始用一维的数据找规律.发现在一维的树上,如果把各边的值合在一起当成一个二进制数,那么,ans只与奇偶性有关,于是,我提出了一个比较大胆的假设:若连接在root上的所 ...

  6. Task6.神经网络基础

    BP: 正向计算loss,反向传播梯度. 计算梯度时,从输出端开始,前一层的梯度等于activation' *(与之相连的后一层的神经元梯度乘上权重的和). import torch from tor ...

  7. linux运维、架构之路-Nginx提高

    一.虚拟主机搭建 1.基于域名的虚拟主机 [root@web01 html]# cat nginx.conf worker_processes ; events { worker_connection ...

  8. bootstrap 前端框架学习笔记

    下面是一个基于 bootstrap 前端架构的最最基本的模板: (这里添加慕课网的学习笔记.) 1.认识一下 bootstrap 带来的优雅效果: 代码: <!DOCTYPE html> ...

  9. python中私有属性的访问

    class MyClass(): def __init__(self): self.__superprivate = "Hello" self.__semiprivate = &q ...

  10. java 中异常类

    算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCastException 数组负下标异常:NegativeAr ...