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 ...
随机推荐
- 【php】 php-fpm 配置见解
来源:php官方文档 Init script setup=== You will probably want to create an init script for your new php-fpm ...
- Linux 磁盘相关
挂载文件系统 mount mount [-t fstype] filesystem dir ##mount /dev/sdb /data 卸载文件系统 umount umount /dev/sdb u ...
- Python9-day2 作业
下列结果是什么? 6 or 2 >1 6 3 or 2 > 1 3 0 or 5<4 false 5 < 4 or 3 3 2 >1 or 6 True 3 ...
- Python3中super()的参数传递
1. super([type[, object-or-type]]) super() 在使用时至少传递一个参数,且这个参数必须是一个类. 通过super()获取到的是一个代理对象,通过这个对象去查找父 ...
- 【20】display,float,position的关系
[20]display,float,position的关系 如果display为none,元素不显示. 否则,如果position值为absolute或者fixed,元素绝对定位,float的计算值为 ...
- kali2018利用ss和ProxyChains实现任意应用代理
第一步:配置ss 第二步:配置proxychain vim /etc/proxychains.conf 第三步:使用proxychains 终端输入: proxychains firefox 通过代理 ...
- Java包(package)详解
java包的作用是为了区别类名的命名空间 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用.. 2.如同文件夹一样,包也采用了树形目录的存储方式.同一个包中的类名字是不同的,不同的包 ...
- Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
G. Fake News (easy) time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【JavaScript 3—基础知识点】:运算符
导读:其实看到这个运算符的学习,很有一种熟悉感,因为在总体看来,和之前的C++有很多类似的地方,但当时觉得简单,没有总结.所以,这次一定得总结了.其实,知识的罗列,基础的积累,在学习中也很重要. 一. ...
- NYOJ-525一道水题思路及详解
一道水题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...