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. C#Stopwatch的简单计时 [收藏]

    Stopwatch 类 命名空间:System.Diagnostics.Stopwatch 实例化:Stopwatch getTime=new Stopwatch(); 开始计时:getTime.St ...

  2. day02-css

    技术分析 HTML的块标签: div标签: 默认占一行,自动换行 span标签: 内容显示在同一行 CSS概述: Cascading Style Sheets : 层叠样式表 主要用作用: 用来美化我 ...

  3. day01-html

    HTML概述: HTML: Hyper Text Markup Language 超文本标记语言 超文本: 比普通文本功能更加强大,可以添加各种样式 标记语言: 通过一组标签.来对内容进行描述. &l ...

  4. nodejs 模板引擎

    自制替换模板 template.js var fs = require('fs') var http = require('http') var server = http.createServer( ...

  5. static作用,静态成员变量和静态成员函数

    static关键字有俩作用:(1).控制存储分配:(2).控制一个名字的可见性和连接.   随着C++名字空间的引入,我们有了更好的,更灵活的方法来控制一个大项目的名字增长.     在类的内部使用s ...

  6. django中collectstatic的使用

    前言 我最近在琢磨django框架的使用,在上传个人网站服务器上时,再次遇到了找不到静态文件,css.img等样式全无的问题.于是沉下心来,好好研究了django的静态文件到底应该怎么去部署(depl ...

  7. 快速排序的python实现

    def quick_sort(array, left, right): if left < right: base_index = division(array, left, right) qu ...

  8. Keyguard分析

      从Android 6.0开始,位于frameworks/bases/packages/Keyguard的Keyguard开始被编译为一个jar包,被SystemUI静态导入,相当于SystemUI ...

  9. 监听UDP端口

    功能:监听服务器的UDP端口,输出端口接收的数据 #encoding:utf-8 import socket global udp global ip global port def listen_p ...

  10. Python_005(字典无极坑)

    一.字典(dict) 1.字典的定义格式:dic{key1:value1,key2,value2} :这里面key是唯一的,保存的时候,根据key计算一个内存地址,然后将key-value保存在这个地 ...