题目:有非常多工人。相应一个能力描写叙述表,每种能力有一个权值,求每一个工人的能力值。

分析:字符串。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的更多相关文章

  1. Hay Points

    Hay Points TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Totalsubmit: 1022   Accepted: 602 Descript ...

  2. POJ 2403 Hay Points

    Hay Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5735   Accepted: 3695 Descri ...

  3. UVA 10869 - Brownie Points II(树阵)

    UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...

  4. UVA 11355 Cool Points(几何)

    Cool Points We have a circle of radius R and several line segments situated within the circumference ...

  5. Problem 1008 Hay Points

    Problem Description Each employee of a bureaucracy has a job description - a few paragraphs that des ...

  6. UVA 11355 Cool Points( 极角计算 )

    We have a circle of radius R and several line segments situated within the circumference of this cir ...

  7. Poj 2403 Hay Points(Map)

    一.题目大意 实现一个工资计算系统.工资的计算规则是:首先,给定一些关键字和对应的价值,这个相对于字典.然后给出的是求职者的描述,如果这个描述中包含关键字则加上对应的价值,总得价值就是这个求职者的工资 ...

  8. UVa 12714 Two Points Revisited (水题,计算几何)

    题意:给定一条线段,让你求一条线段与已知线段垂直,并且所有线段的坐标的点的坐标都不大于给定的坐标的最大值且不能为负数. 析:没啥好说的,随便找一条就好. 代码如下: #pragma comment(l ...

  9. ACM学习

    转:ACM大量习题题库   ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库.   US ...

随机推荐

  1. python 中requests 模块用py2exe生成exe后SSL certificate exception的问题

    [('system library', 'fopen', 'No such process'), ('BIO routines', 'BIO_new_file', 'no such file'), ( ...

  2. mysql复制延迟排查

    今天收到报警,提示从库延时,首先当然是上去查看情况,首先查看机器负载,如下: 可以看到使用cpu已经100%,io没有等待.那么查看mysql是什么情况,执行show processlist没有发现任 ...

  3. List<T> List<?> 区别用法

    List<T>是泛型方法,List<?>是限制通配符 List<T>一般有两种用途:1.定义一个通用的泛型方法.伪代码: public interface Dao{ ...

  4. SQLAlchemy常用操作

    Models 只是配置和使用比较简单,因为他是Django自带的ORM框架,也正是因为是Django原生的,所以兼容性远远不如SQLAlchemy 真正算得上全面的ORM框架必然是我们的SQLAlch ...

  5. linux救援

    1.单用户模式(类比win的安全模式) 1.1.开机按任意键 1.2.按E进入编辑模式 1.3.光标移动到第二个(“kernel xxxx”)按e 1.4.在quiet 后面输入“ 1” or “S” ...

  6. luogu2483 【模板】k短路([SDOI2010]魔法猪学院)

    模板题 #include <iostream> #include <cstring> #include <cstdio> #include <queue> ...

  7. 九度oj 题目1385:重建二叉树

    题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...

  8. iOS学习笔记19-地图(一)定位CoreLocation

    一.定位介绍 现在很多社交.电商.团购应用都引入了地图和定位功能,似乎地图功能不再是地图应用和导航应用所特有的.的确,有了地图和定位功能确实让我们的生活更加丰富多彩,极大的改变了我们的生活方式.要实现 ...

  9. 【Luogu】P2331最大子矩阵(DP)

    题目链接 这题的状态转移方程真是粗鄙. f[i][j][k]表示前i行用了j个矩阵状态为k的时候的最大值. k=0:两列都不选. k=1:取左弃右. k=2:选右弃左. k=3:左右都选,但分属于两个 ...

  10. 625. Minimum Factorization

    Problem statement Given a positive integer a, find the smallest positive integer b whose multiplicat ...