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 ...
随机推荐
- 51nod 1050 循环数组最大子段和 (dp)
http://www.51nod.com/onlineJudge/questionCode.html#problemId=1050¬iceId=13385 参考:http://blog. ...
- MV、MVC、MVP、MVVM简介,对MVC不确定了。
参考: http://www.cnblogs.com/changxiangyi/archive/2012/07/16/2594297.html http://www.jcodecraeer.com/a ...
- leetcode Database2 (四)
一.Duplicate Emails Write a SQL query to find all duplicate emails in a table named Person. +----+--- ...
- XML中对特殊字符的处置
str = str.replaceAll("‘", "‘"); str = str.replaceAll("’", "‘" ...
- UVa 644 Immediate Decodability
吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂. 题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子 ...
- 51nod1084 矩阵取数问题 V2
O(n4)->O(n3)妈呀为什么跑这么慢woc #include<cstdio> #include<cstring> #include<cctype> #i ...
- 51nod1294 修改数组
看题解的...就是将必须要修改的数去掉后求最长的不递减子序列. upper_bound+lower_bound要理解.有时候-1有时候不用是有原因的. #include<cstdio> # ...
- 51nod1757 大灾变
能想到二分答案+最大流判断是否符合.但是不知道如何建图qaq.参考的是http://blog.csdn.net/fsss_7/article/details/52132046的建图方法 #includ ...
- 集成框架jar包的一些选择
我们往往在官网上下载了框架需要的jar却不知道该导入什么. required包里面的是必须导入的jar jar应该一切从简
- BZOJ 2303 方格染色
首先考虑四个格子异或值为1. 然后(重点)发现每个格子的值只和最上面,最左边,和(1,1)的格子的颜色有关. 枚举(1,1)的颜色,联立方程,可以将未知数减少,那么并查集可做. 最后算答案的时候,有些 ...