题目链接

题意: 给出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. [原]poj-2488-water-DFS

    题目大意: 输入一个p*q的棋盘, 行用数字表示, 列用大写字母表示 , 1 <= p*q <= 26, 输出能够把棋盘全部空格走完且每个空格只走一次的字典序最小的路径.不存在则输出“im ...

  2. hihoCoder 1039字符消除 (字符串处理)

    http://hihocoder.com/problemset/problem/1039 因为字符串只由3种字母组成,并且插入的字符也只能是这三种字符的其中一个,那么可以考虑枚举这三个字符其中一个字符 ...

  3. IO(二)

    package com.bjsxt.io.buffered; import java.io.BufferedInputStream; import java.io.BufferedOutputStre ...

  4. C#图片切割、图片压缩、缩略图生成

    C#图片切割.图片压缩.缩略图生成的实现代码 /// 图片切割函数  /// </summary>  /// <param name="sourceFile"&g ...

  5. 了解thinkphp(二)

    ThinkPHP的核心文件: Library文件夹下的Think文件夹目录 ThinkPHP的入口文件是: ThinkPHP.php , 我们在创建项目时都要引入这个入口文件!!! 一 , 项目的部署 ...

  6. shell进行mysql统计

    array=(江苏 浙江 新疆 宁夏 广东 福建 重庆 江西 吉林 湖南 山东 云南  上海 河北 黑龙江 北京 四川 河南 山西 湖北 辽宁 安徽 陕西 广西 贵州 内蒙古 天津 甘肃 海南 青海 ...

  7. WP7应用版本升级的实现方法

    首先必须要有一个服务提供升级推送查询 // Code to execute when the application is launching (eg, from Start)         //  ...

  8. spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

    在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...

  9. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  10. C实现类封装、继承、多态

    1.  概述 C语言是一种面向过程的程序设计语言,而C++是在C语言基础上衍生来了的面向对象的语言,实际上,很多C++实现的底层是用C语言实现的,如在Visual C++中的Interface其实就是 ...