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 ...
随机推荐
- iPhone —— 如何自制铃声(图文)
iPhone不像其他手机可以直接将MP3格式的文件设为铃声.但如果想用自己喜欢的歌曲作为铃声该怎么办呢?请听我一一道来. 一.将MP3文件转换成iPhone铃声能识别的M4R格式文件 1.向iTune ...
- Vim 新用法
daw , delete a word cw , delete from cursor to the end then insert mode a word 移动: f ; Aa Oo Cc Ii S ...
- HDU 4744 Starloop System(ZKW费用流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4744 题意:三维空间n个点,每个点有一个wi值.每对点的距离定义为floor(欧拉距离),每对点之间建 ...
- Perl文件读写
Perl File Handling: open, read, write and close files #==================== Opening files Solution 1 ...
- tc srm 632 500 (规律)
We have a sequence of N positive integers: a[0] through a[N-1]. You do not know these integers. All ...
- Linux进程控制(一)
1. Linux进程概述 进程是一个程序一次执行的过程,它和程序有本质区别.程序是静态的,它是一些保存在磁盘上的指令的有序集合:而进程是一个动态的概念,它是一个运行着的程序,包含了进程的动态创建.调度 ...
- HDU 1072 (不一样的入队条件) Nightmare
之前的BFS都是需要一个标记数组,但这个题不一样,因为可能一个格子不止走一次. 那么我们就要寻找新的入队条件:left比上次经过的时候大才入队(left表示上次经过该点时剩余的时间). 为什么呢?我们 ...
- asp.net下通过泛解析和伪静态实现二级域名的实现方法
在net中微软已经为我们留下了接口,让我们为所欲为了. 首先我们可以通过一张图大概了解下.net的生命周期. 从 上图可以看出来,针对每个不同用户的请求,服务器都会创建一个新的HttpContext实 ...
- 正则化,数据集扩增,Dropout
正则化方法:防止过拟合,提高泛化能力 在训练数据不够多时,或者overtraining时,常常会导致overfitting(过拟合).其直观的表现如下图所示,随着训练过程的进行,模型复杂度增加,在tr ...
- textarea高度自适应
var tx=document.getElementById("tx"); tx.style.height=tx.scrollHeight+"px" tx.st ...