stl应用(map)或字典树(有点东西)
M - Violet Snow
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?
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
1
3 5
dollar 0.71
euro 0.76
turkish 0.17
5.1 dollar
6 dollar
7 turkish
3 euro
1.1 JD
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)或字典树(有点东西)的更多相关文章
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...
- 51nod 1095 Anigram单词【hash/map/排序/字典树】
1095 Anigram单词 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b ...
- STL中map与hash_map容器的选择收藏
这篇文章来自我今天碰到的一个问题,一个朋友问我使用map和hash_map的效率问题,虽然我也了解一些,但是我不敢直接告诉朋友,因为我怕我说错了,通过我查询一些帖子,我这里做一个总结!内容分别来自al ...
- STL中map与hash_map的比较
1. map : C++的STL中map是使用树来做查找算法; 时间复杂度:O(log2N) 2. hash_map : 使用hash表来排列配对,hash表是使用关键字来计算表位置; 时间复杂度:O ...
- poj2513--并查集+欧拉路+字典树
经典好题,自己不知道哪里错了交上去是RE,可能是数组开的不好吧,字典树老碰到这种问题.. 先马上别人的代码,有空对拍看看 #include <cstdio> #include <cs ...
- HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...
- poj 2503 Babelfish(字典树或map或哈希或排序二分)
输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...
- 洛谷 P3370 【模板】字符串哈希 (set||map||哈希||字典树(mle)
P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. #友情提醒:如果真的想好 ...
随机推荐
- AOP拦截日志类,抛异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
AOP的日志拦截类中,抛出异常: java.lang.IllegalStateException: It is illegal to call this method if the current r ...
- nginx-博客阅读笔记记录-20190916
Nginx 入门学习教程 Ng官网解释: nginx [engine x]是最初由Igor Sysoev编写的HTTP和反向代理服务器,邮件代理服务器和通用TCP / UDP代理服务器. 维基百科解释 ...
- Wannafly挑战赛27 D绿魔法师
链接Wannafly挑战赛27 D绿魔法师 一个空的可重集合\(S\),\(n\)次操作,每次操作给出\(x,k,p\),要求支持下列操作: 1.在\(S\)中加入\(x\). 2.求\[\sum_{ ...
- GC、进程和线程的定义
GC是什么,为什么要有GC GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方,忘记或者错误的内存回收会导致程序或系统的不稳定甚至崩溃.Java提供的GC ...
- python学习笔记(九)内置函数
print(all([1,2,3,4]))#判断可迭代的对象里面的值是否都为真 True print(any([0,1,2,3,4]))#判断可迭代的对象里面的值是否有一个为真 True print( ...
- linux运维、架构之路-正则表达式
一.通配符的含义 符号 参数说明 其他说明 | 管道 把前一个命令结果通过管道传递给后面一个命令 ; 命令的分隔符 ll /oldboy/;cat oldboy.tx . 表示当前目录 * 匹配文本或 ...
- Jenkins必备插件
1.汉化插件 https://plugins.jenkins.io/localization-zh-cn 2.邮件发送 https://plugins.jenkins.io/email-ext 3.G ...
- 【説明する】DS
其实就是数据结构课后题整理....只会一个是什么鬼 染色问题: 线段树? 功能太强大了! 我们并不需要那么多的功能 运用并查集!!! 将相同的并为一段 BZOJ 2375(讲真我没找到这个题在哪里.. ...
- MapServer教程2
第二章 Tutorial 教程 MapServer Tutorial MapServer教程 Tutorial background 教程背景 Section 1: Static Maps and t ...
- 20180826(02)-Java集合框架
Java 集合框架 早在Java 2中之前,Java就提供了特设类.比如:Dictionary, Vector, Stack, 和Properties这些类用来存储和操作对象组. 虽然这些类都非常有用 ...