HDU 2648 Shopping【映射/字符串哈希】
发布日期:2021-07-01 02:50:54
浏览次数:2
分类:技术文章
本文共 1670 字,大约阅读时间需要 5 分钟。
Problem Description
Every girl likes shopping, so does dandelion.Now she finds the shop is increasing the price every day because the Spring Festival is coming .She is fond of a shop which is called"memory"
. Now she wants to know the rank of this shop’s price after the change of everyday. Input
One line contians a numbern(n <= 10000)
, stands for the number of shops. Then n
lines ,each line contains a string (the length is short than 31
and only contains lowercase letters and capital letters.) stands for the name of the shop. Then a line contians a number m(1<= m <= 50)
, stands for the days. Then m
parts , every parts contians n
lines, each line contians a number s
and a string p
, stands for this day, the shop p's
price has increased s
. Output
Containsm
lines, In the ith
line print a number of the shop "memory"
‘s rank after the ith
day. We define the rank as: If there are t
shops’ price is higher than the "memory"
, than its rank is t+1
. Sample Input
3memorykfcwind249 memory49 kfc48 wind80 kfc85 wind83 memory
Sample Output
12
题意:给出 n
家店铺 m
天的价格增长,输出 "memory"
这家店每天的价格排名。
思路:用 map
容器操作。唯一需要注意的是,有多组测试数据。代码如下:
#includeusing namespace std;const int maxn = 40;char str[maxn]; int main() { int n, m, price; while (~scanf("%d", &n)) { unordered_map shops; for (int i = 1; i <= n; ++i) //输入店铺名字,不用做处理 scanf("%s", str); scanf("%d", &m); while (m--) { int rank = 1; for (int i = 1; i <= n; ++i) { scanf("%d%s", &price, str); shops[str] += price; } for (const auto &it : shops) if (it.second > shops["memory"]) ++rank; printf("%d\n", rank); } } return 0;}
另外,还会使用字符串哈希来做这一道题。
转载地址:https://memcpy0.blog.csdn.net/article/details/108347419 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月24日 09时52分42秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
使用aspose.words 18.6实现pdf文档转换
2019-05-01
Java数组详解
2019-05-01
vs中动态DLL与静态LIB工程中加入版本信息的方法
2019-05-01
大数据分析技术与应用一站式学习(值得收藏)_v20200418
2019-05-01
Qt 在windows下的串口读写
2019-05-01
SpringApplication执行流程
2019-05-01
自定义Starter
2019-05-01
分布式事务原理探究(一)
2019-05-01
spring cloud consul 应用的多实例名的解决
2019-05-01
人工智能为什么这么火?看看安防江湖30年血战就知道了
2019-05-01
“前端智能为安防产生新的数据价值”
2019-05-01
(8)CMake入门笔记--CMake语法
2019-05-01
头文件中 #ifndef---#define---#endif的作用
2019-05-01
Ant内置任务之whichresource
2019-05-01
Ant内置任务之symlink
2019-05-01
深入理解python--线程、进程与协程(1)
2019-05-01
Java--流重点总结初稿
2019-05-01
字符串的排序
2019-05-01
内存分配(mallloc,calloc,realloc,new)
2019-05-01