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. vue中的scope

    在vue文件中的style标签上,有一个特殊的属性:scoped. 当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组件元素. 通过该属 ...

  2. HTML拖放元素

    实现来回拖放图片 <!DOCTYPE HTML> <html> <title>来回拖放元素</title> <meta charset=" ...

  3. jQuery学习总结05-事件

    1.事件的发生 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. wordpress系统网站访问慢的解决方案

    从2013年5月底开始,google在中国基本处于无法访问状态,谷歌官网 域名,香港域名均无法访问,就连之前的IP访问方法也都失效,而Google Adsense打不开,恐怕做谷歌联盟的站长也要倒霉了 ...

  5. pg_config - 检索已安装版本的 PostgreSQL 的信息

    SYNOPSIS pg_config {--bindir | --includedir | --includedir-server | --libdir | --pkglibdir | --confi ...

  6. OCTAVE-CONFIG

    SYNOPSIS 总览 octave-config [--m-site-dir] [--oct-site-dir] [-v|--version] [-h|-?|--help] DESCRIPTION ...

  7. LinuxC语言实现服务端与客户端多进程通信

    链接:https://pan.baidu.com/s/1YDNIyTKAkh4E5x2dBeTgcQ 提取码:y35q 复制这段内容后打开百度网盘手机App,操作更方便哦 本实验用的是Centos7m ...

  8. Spring Cloud Stream监听已存在的Queues/Exchanges

    环境准备 rabbitmq已运行,端口5672,控制台web端口15672,用户名密码guest/guest 引入spring cloud stream依赖 compile('org.springfr ...

  9. Debug to add expression

    Debug expression

  10. 23飞机大战__pygame 快速入门

      1. 使用 pygame 创建图形窗口 小节目标 游戏的初始化和退出 理解游戏中的坐标系 创建游戏主窗口 简单的游戏循环 可以将图片素材 绘制 到 游戏的窗口 上, 开发游戏之前需要先知道 如何建 ...