题目链接

题意: 给出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)的更多相关文章

  1. Shopping(山东省第一届ACM省赛)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  2. sdutoj 2154 Shopping

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154 Shopping Time Limit: ...

  3. Shopping(SPFA+DFS HDU3768)

    Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. eclipse中 起动tomcat时报Multiple Contexts have a path of "/shopping"

    eclipse中 启动tomcat时报Multiple Contexts have a path of "/shopping". 这个是由于你的server服务器中的server. ...

  5. 洛谷P2732 商店购物 Shopping Offers

    P2732 商店购物 Shopping Offers 23通过 41提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 在商店中, ...

  6. UVALive - 6572 Shopping Malls floyd

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48416 Shopping Malls Time Limit: 3000MS 问题描述 We want to ...

  7. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  8. 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 ...

  9. poj 1170 Shopping Offers

    Shopping Offers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4696   Accepted: 1967 D ...

随机推荐

  1. [CCF2015.09]题解

    201509-1 数列分段 水,记下前一个数,看看跟当前是否一样,不一样就ans+1 #include <algorithm> #include <iostream> #inc ...

  2. [CF660C]Hard Process(尺取法)

    题目链接:http://codeforces.com/problemset/problem/660/C 尺取法,每次遇到0的时候补一个1,直到补完或者越界为止.之后每次从左向右回收一个0点.记录路径用 ...

  3. 浅析JavaScript之Function类型

    JavaScript中的函数实际上是对象,每个函数都是Function类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对象,因此函数名实际上只是指向函数对象的指针,保存函数在堆内存中的地 ...

  4. short s1 = 1; s1 = s1 + 1;和 s1 += 1;

    对于short s1 = 1; s1 = s1 + 1; 由于s1+1运算时会自动提升表达式的类型,所以结果是int型,再赋值给short类型s1时,编译器将报告需要强制转换类型的错误. 对于shor ...

  5. /bin/bash: [xxxx]: command not found

    /******************************************************************************** * /bin/bash: [xxxx ...

  6. Java 碰撞的球 MovingBall (整理)

    package demo; /** * Java 碰撞的球 MovingBall (整理) * 声明: * 这份源代码没有注释,已经忘记了为什么要写他了,基本上应该是因为当时觉得好玩吧. * 有时候想 ...

  7. matlab注释使用,以及相应的注释快捷键

    1.多行注释 单行注释是加% %{ 若干语句 %} 2.快捷键 多行注释: 选中要注释的若干语句, 编辑器菜单Text-<Comment, 或者快捷键Ctrl+R 取消注释: 选中要取消注释的语 ...

  8. Mac下配置环境变量

    1.创建并以 TextEdit 的方式打开 ~/.bash_profile 文件,如果没有则 touch ~/.bash_profile; 然后打开 vim ~/.bash_profile 2.新增环 ...

  9. 【英语】Bingo口语笔记(39) - Get系列

  10. 关闭iptables(Centos)

    由于搭建了CDH-Hadoop,方便起见,事先关闭了防火墙: services iptables stop; chkconfig iptables off; services ip6tables st ...