HDU 2648 Shopping
2016-05-07 22:35
369 查看
题目分析
这里的题目意思我就不啰嗦了,利用map进行处理,并用hash的思想更快更简单地解决问题,详情看代码。#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <map> using namespace std; map <string, int> change; //将字符串转化为整型值利于处理 int has[10005]; //hash表用来存储每个字符串对应的商店的价格 int main() { int n,m; string s; while(scanf("%d", &n) != EOF) { memset(has, 0, sizeof(has)); int flag,increase; for(int i = 1; i <= n; i++) { cin >> s; change[s] = i; //直接这样写或者change.insert(pair<string,int>(s,i)),不懂的看一下map的用法 if(s == "memory") flag = i; } scanf("%d", &m); while(m--) { for(int i = 1; i <= n; i++) { cin >> increase >> s; //将对应商场的价格增加increase; has[change[s]] += increase; } int sum = 0; for(int i = 1; i <= n; i++) //找到对应的位置 if(has[i] > has[flag]) sum++; printf("%d\n", sum+1); } } return 0; }
相关文章推荐
- opencv图像映射
- 20150306+Linux安装+常用命令-02
- 20150306+Linux安装+常用命令-01
- 百万用户级游戏服务器架构设计(二)
- Opencv3.1+Ubuntu15.10
- /var/log目录下的20个Linux日志文件功能详解
- scanf()函数键盘缓冲区残余信息的问题!!!
- linux下exit()和_exit()区别
- Apache Flink源码解析之stream-sink
- centos 7 安装无线网卡rtl8188EUS_rtl8189ES驱动
- nginx-rtmp-module安装笔记
- Linux入门之入手开发板与开发环境的搭建 2016.5.7
- linux jenkins安装(四)
- opencv3.0 FaceRecongnizer说明
- 百万用户级游戏服务器架构设计(一)
- 杂谈嵌入式linux和单片机开发
- 用到的网站(持续更新)
- linux maven安装(三)
- (OK) Fedora 23——CORE——docker——(5)——> install-core
- (OK) Fedora 23——CORE——docker——(4)——> iptables_core.sh