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 ...
随机推荐
- 【mysql】配置 选项文件
在Windows中,MySQL程序从以下文件读取启动选项: 文件名 目的 WINDIR\my.ini 全局选项 C:\my.cnf 全局选项 INSTALLDIR\my.ini 全局选项 defaul ...
- python--操作系统介绍,进程的创建(并发)
一 . 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 二 多道技术: 所谓多道程序设计技术,就是指允许多个程序同时进入内存 ...
- LeetCode(118) Pascal's Triangle
题目 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, R ...
- ZOJ 3469 区间DP Food Delivery
题解 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm ...
- joyoi1864 守卫者的挑战
#include <algorithm> #include <iostream> #include <cstdio> using namespace std; in ...
- python linux安装anaconda
步骤: 1.在清华大学镜像站中下载anaconda版本:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ https://mirrors.t ...
- excel截取某个字符之前的值
1.find为查找函数,返回字符的位置,语法find(查找字符,被查字符或者单元格) 找到第一个-位置 2.left,字符截取函数,从左边开始,left(被截取的字符,个数)
- Title共通写法
用: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_c ...
- Codeforces 895.A Pizza Separation
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...
- P2015 二叉苹果树 (树形动规)
题目描述 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点) 这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1. 我们用一根树枝两端连接的结点的编号来 ...