HDU2648:Shopping(DKBR_hash)
题意: 给出n个字符串,接下来m天,每天每个字符串要增加对应的值,询问“memory”每天的排名
分析:
用hash表hash出每个字符串对应得值,然后放入二维数组(防止地址冲突),m天,输入字符串,查找并处理,最后用一个数组记录每次得值
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int mod = ;
struct node
{
char s[];
int value;
}a;
int n,m,x,ret,now_value,now_size,xx,p[];
char s1[];
vector<node>g[+];
int get_hash(char *str)
{
int ret=;
while(*str) ret=ret*+*str++;
return ret&0x7fffffff%mod;
}
int main()
{
while(scanf("%d",&n)==)
{
for(int i=;i<;++i) g[i].clear();
for(int i=;i<=n;++i)
{
scanf("%s",s1);
strcpy(a.s,s1);a.value=;
g[get_hash(s1)].push_back(a);
}
scanf("%d",&m);
while(m--)
{
int cnt=;
for(int i=;i<=n;++i)
{
scanf("%d %s",&x,s1);
now_value=get_hash(s1);
now_size=g[now_value].size();
for(int j=;j<now_size;++j) if(strcmp(g[now_value][j].s,s1)==)
{
g[now_value][j].value+=x;
ret=g[now_value][j].value;
break;
}
if(strcmp(s1,"memory")==) xx=ret;else p[++cnt]=ret;
}
int ans=;
for(int i=;i<=cnt;++i) if(p[i]>xx) ans++;
printf("%d\n",ans+);
}
}
}
-END-
HDU2648:Shopping(DKBR_hash)的更多相关文章
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdutoj 2154 Shopping
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154 Shopping Time Limit: ...
- Shopping(SPFA+DFS HDU3768)
Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- eclipse中 起动tomcat时报Multiple Contexts have a path of "/shopping"
eclipse中 启动tomcat时报Multiple Contexts have a path of "/shopping". 这个是由于你的server服务器中的server. ...
- 洛谷P2732 商店购物 Shopping Offers
P2732 商店购物 Shopping Offers 23通过 41提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 在商店中, ...
- UVALive - 6572 Shopping Malls floyd
题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
- Codeforces Round #332 (Div. 2) A. Patrick and Shopping 水题
A. Patrick and Shopping Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- poj 1170 Shopping Offers
Shopping Offers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4696 Accepted: 1967 D ...
随机推荐
- < %=...%>< %#... %>< % %>< %@ %>具体意义
< %=...%>< %#... %>< % %>< %@ %>< %#... %>: 是在绑定控件DataBind()方法执行时被执行,用 ...
- Form.ShowDialog和Form.DialogResult
The dialog result of a form is the value that is returned from the form when it is displayed as a mo ...
- vs中常用的快捷键
VS中常用的快捷键: ctrl+s 保存 ctrl+Shift+S 保存所有VS中打开的所有文件 ctrl+O 打开新文件 ctrl+Shift+O 打开项目 ...
- 《OD大数据实战》MapReduce实战
一.github使用手册 1. 我也用github(2)——关联本地工程到github 2. Git错误non-fast-forward后的冲突解决 3. Git中从远程的分支获取最新的版本到本地 4 ...
- 第四讲:hibernate 的session (二)
Session在hibernate中表示连接.下面介绍他的常用方法. 在使用前先把最重要的说了.打开API,发现在session中基本所有的方法(包括获得session的方法)都会抛出异常Hibern ...
- plsql programming 19 触发器
挂起语句, 是指数据库 Hang 到那不能动了, 触发的. 1. DML 触发器 这种类型的触发器对于开发人员都很常见, 其他类型的触发器主要是给DBA使用的. 配置触发器,我们需要回答以下问题: 触 ...
- OpenStack介绍
简介 OpenStack是一个开源的云计算管理平台项目,由几个主要的组件组合起来完成具体工作.OpenStack支持几乎所有类型的云环境,项目目标是提供实施简单.可大规模扩展.丰富.标准统一的云计算管 ...
- VS2008下使用 CMFCPropertyGridCtrl 转载
http://blog.csdn.net/sunnyloves/article/details/5655575 在DLG中的基本应用 . 首先在Cxxdlg.h文件中加入 public: CMFCPr ...
- typedef struct trx_struct trx_t;
/* The transaction handle; every session has a trx object which is freed only when the session is fr ...
- 如何直接在github网站上更新你fork的repo?
玩过github的人一定会在你自己的账号上fork了一些github开源项目.这些开源项目往往更新比较活跃,你今天fork用到你自己的项目中去了,过几个星期这个fork的origin可能有一些bugf ...