UVa 10295 - Hay Points
题目:有非常多工人。相应一个能力描写叙述表,每种能力有一个权值,求每一个工人的能力值。
分析:字符串。hash表,字典树。利用散列表或者字典树存储相应的单词和权值。查询就可以。
说明:注意初始化,计算完将数据清除。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> using namespace std; //hash_define
typedef struct hnode
{
char words[20];
int value;
hnode* next;
}hash;
hash hash_node[2001];
hash* hash_table[2005];
int hash_size; int hash_initial()
{
hash_size = 0;
memset(hash_table, 0, sizeof(hash_table));
memset(hash_node, 0, sizeof(hash_node));
} int hash_value(char *str)
{
int value = 0;
for (int i = 0 ; str[i] ; ++ i) {
value = value*26%1000;
value += str[i];
}
return value;
} int hash_insert(char *str, int val)
{
int value = hash_value(str);
hash_node[hash_size].value = val;
strcpy(hash_node[hash_size].words, str);
hash_node[hash_size].next = hash_table[value];
hash_table[value] = &hash_node[hash_size ++];
} int hash_find(char *str)
{
int value = hash_value(str);
for (hash* p = hash_table[value] ; p ; p = p->next)
if (!strcmp(p->words, str))
return p->value;
return 0;
}
//hash_end int main()
{
int m,n,v;
char buf[2001];
while (~scanf("%d%d",&m,&n)) {
hash_initial();
for (int i = 0 ; i < m ; ++ i) {
scanf("%s%d",buf,&v);
hash_insert(buf, v);
} for (int i = 0 ; i < n ; ++ i) {
int sum = 0;
while (~scanf("%s",buf)) {
if (!strcmp(buf, "."))
break;
sum += hash_find(buf);
}
printf("%d\n",sum);
}
}
return 0;
}
UVa 10295 - Hay Points的更多相关文章
- Hay Points
Hay Points TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 1022 Accepted: 602 Descript ...
- POJ 2403 Hay Points
Hay Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5735 Accepted: 3695 Descri ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
- UVA 11355 Cool Points(几何)
Cool Points We have a circle of radius R and several line segments situated within the circumference ...
- Problem 1008 Hay Points
Problem Description Each employee of a bureaucracy has a job description - a few paragraphs that des ...
- UVA 11355 Cool Points( 极角计算 )
We have a circle of radius R and several line segments situated within the circumference of this cir ...
- Poj 2403 Hay Points(Map)
一.题目大意 实现一个工资计算系统.工资的计算规则是:首先,给定一些关键字和对应的价值,这个相对于字典.然后给出的是求职者的描述,如果这个描述中包含关键字则加上对应的价值,总得价值就是这个求职者的工资 ...
- UVa 12714 Two Points Revisited (水题,计算几何)
题意:给定一条线段,让你求一条线段与已知线段垂直,并且所有线段的坐标的点的坐标都不大于给定的坐标的最大值且不能为负数. 析:没啥好说的,随便找一条就好. 代码如下: #pragma comment(l ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
随机推荐
- python基础知识14-正则表达式
1.正则表达式 正则可以代替其他任何工具,但是其他工具不能完全代替正则. 1.匹配或提取字符串的工具,基于所有语言之上的工具. 正则表达式所面向的问题 判断一个字符串是否匹配给定的格式,如判断用户注册 ...
- LeetCode(113) Path Sum II
题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...
- Python模块--time&datetime
一.Python中时间的表示方式 1.时间戳 如 1552623413.043036 2.格式化的时间字符串 如 2015-12-02 3.struct_time 是一个元组 共有九个元素 二. ...
- Knockout v3.4.0 中文版教程-11-控制文本内容和外观-text绑定
2. text绑定 目的 text绑定把传入的参数通过关联的DOM元素来显示文本值. 通常这对像<span>或<em>标签等使用,但技术上你可以对任何元素使用该绑定. 例子 T ...
- vs系列自带的localdb数据库当做数据库
我在学习mvc4框架的时候,因为是笔记本,觉得装了一个vs就很大了,再装一个sql server 就更麻烦,因此,就想到使用vs自带的localDB,直接生成预览的时候是没有问题的,但是当把mvc4的 ...
- Java-字符转比较
实用的字符串比较方法 package com.tj; public class MyClass implements Cloneable { public static void main(Strin ...
- HDU-5317 RGCDQ ,暴力打表!
RGCDQ 暴力水题,很可惜比赛时没有做出来,理清思路是很简单的. 题意:定义f(i)表示i的素因子个数,给你一段区间[l,r],求max_gcd(f(i),f(j)).具体细节参考题目. 思路:数据 ...
- 九度oj题目1008:最短路径问题
题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的. 输入: ...
- 【luogu】P1772物流运输(最短路+DP)
题目链接 对于本题我们设ext[i][j]计算第i个码头在前j天总共有几天不能用(其实就一前缀和),设dis[i][j]是从第i天到第j天不变运输路线的最短路径,设f[i]是前i天运输货物的最小花费. ...
- BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积
[题目分析] 卷积一卷. 然后分块去一段一段的求. O(n)即可. [代码] #include <cstdio> #include <cstring> #include < ...