hdu 1880 魔咒词典 (字符串哈希)
魔咒词典
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9381 Accepted Submission(s):
2405
给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中,就输出“what?”
[魔咒]
对应功能
其中“魔咒”和“对应功能”分别为长度不超过20和80的字符串,字符串中保证不包含字符“[”和“]”,且“]”和后面的字符串之间有且仅有一个空格。词典最后一行以“@END@”结束,这一行不属于词典中的词条。
词典之后的一行包含正整数N(<=1000),随后是N个测试用例。每个测试用例占一行,或者给出“[魔咒]”,或者给出“对应功能”。
[rictusempra] send a jet of silver light to hit the enemy
[tarantallegra] control the movement of one's legs
[serpensortia] shoot a snake out of the end of one's wand
[lumos] light the wand
[obliviate] the memory charm
[expecto patronum] send a Patronus to the dementors
[accio] the summoning charm
@END@
4
[lumos]
the summoning charm
[arha]
take me to the sky
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- using namespace std;
- const int MAX = ;
- bool Hash1[MAX];
- bool Hash2[MAX];
- int num1[MAX],num2[MAX];
- int val1[MAX],val2[MAX];
- char xx1[][];int xlen1,cur;
- char xx2[][];int xlen2;
- void Insert(int x,bool *hash,int *num,int *val,int len)
- {
- int k=x%MAX;
- while(hash[k]==true && num[k]!=x)
- {
- k++;
- if(k==MAX) k=k-MAX;
- }
- if(hash[k]==false)
- {
- hash[k]=true;
- num[k]=x;
- val[k]=len;
- }
- }
- bool found(int x,bool *hash,int *num,int *val)
- {
- int k=x%MAX;
- while(hash[k]==true && num[k]!=x)
- {
- k++;
- if(k==MAX) k=k-MAX;
- }
- if(num[k]==x)
- {
- cur=val[k];
- return true;
- }
- return false;
- }
- // ELF Hash Function
- unsigned int ELFHash(char *str)
- {
- unsigned int hash = ;
- unsigned int x = ;
- while (*str)
- {
- hash = (hash << ) + (*str++);
- if ((x = hash & 0xF0000000L) != )
- {
- hash ^= (x >> );
- hash &= ~x;
- }
- }
- return (hash & 0x7FFFFFFF);
- }
- int main()
- {
- char c[],b[];
- int i,j,k,n,m;
- while(gets(c))
- {
- xlen1=-;
- xlen2=-;
- memset(Hash1,false,sizeof(Hash1));
- memset(Hash2,false,sizeof(Hash2));
- memset(num1,-,sizeof(num1));
- memset(num2,-,sizeof(num2));
- while(strcmp(c,"@END@")!=)
- {
- n=strlen(c);
- for(i=,j=;i<n;i++)
- {
- b[j++]=c[i];
- if(c[i]==']')
- {
- b[--j]='\0';
- k=ELFHash(b);
- xlen1++;
- Insert(k,Hash1,num1,val1,xlen1);
- strcpy(xx1[xlen1],b);
- break;
- }
- }
- k=ELFHash(c+i+);
- xlen2++;
- Insert(k,Hash2,num2,val2,xlen2);
- strcpy(xx2[xlen2],c+i+);
- gets(c);
- }
- scanf("%d",&m);
- getchar();
- while(m--)
- {
- gets(c);
- n=strlen(c);
- if(c[]=='[')
- {
- c[n-]='\0';
- k=ELFHash(c+);
- if( found(k,Hash1,num1,val1) )
- printf("%s\n",xx2[cur]);
- else printf("what?\n");
- }
- else
- {
- k=ELFHash(c);
- if( found(k,Hash2,num2,val2) )
- printf("%s\n",xx1[cur]);
- else printf("what?\n");
- }
- }
- }
- return ;
- }
hdu 1880 魔咒词典 (字符串哈希)的更多相关文章
- HDU 1880 魔咒词典 (字符串hash)
<题目链接> 题目大意: 就是每个字符串有一个配套的对应字符串,询问的时候,无论输出其中的哪一个字符串,输出另一个,如果不存在这个字符串,直接输出"what?". 解题 ...
- hdu 1880 魔咒词典
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1880 魔咒词典 Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有10 ...
- HDU 1880 魔咒词典(字符串哈希)
题目链接 Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...
- HDU - 1880 魔咒词典~哈希入门
哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词 ...
- HDU 1880 魔咒词典 (Hash)
魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 1880 魔咒词典(双hash)
魔咒词典Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 1880 魔咒字典
https://vjudge.net/problem/HDU-1880 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...
- 魔咒词典 HDU - 1880 (字符串hash 单hash转int或者 双hash )
哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词 ...
- 魔咒词典(hdu 1880)
Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔 ...
随机推荐
- Qt5学习笔记(消息基础)
#include "MyWidget.h" #include <QApplication> #include <QEvent> #include <Q ...
- cnpm安装过程中提示optional install error: Package require os(darwin) not compatible with your platform(win32)解决方法
运行cnpm install后,出现 虽然提示不适合Windows,但是问题好像是sass loader出问题的.所以只要执行下面命令即可: 方案一: cnpm rebuild node-sass # ...
- Hibernate 查询数据库中的数据
1.Criteria介绍 Criteria与Session绑定,其生命周期跟随着Session结束而结束,使用Criteria时进行查询时,每次都要于执行时期动态建立物件,并加入各种查询条件,随着Se ...
- 将python的代码文件打包成可执行文件
1.使用pip install Pyinstaller 命令安装 2.使用命令 pyinstaller -F *.py打包成exe 3.在\dist文件夹下找到exe; 一.pyinstaller ...
- orcal创建序列
CREATE SEQUENCE flowjobseq --序列名INCREMENT BY 1 -- 每次加几个 START WITH 2000 -- 从1开始计数 NOMAXVALUE -- 不设置最 ...
- Django环境搭建之hello world
当我们想用Python来开发一个web应用时,首先要选择一个优秀的web框架,Django是个非常成熟的web开发框架,网上具有丰富的文档和学习资料,所以选择Django框架来入门web开发是个不错的 ...
- 最新版IntelliJ IDEA2019.1破解教程(2019.04.08更新)
[原文链接]:https://www.tecchen.xyz/idea-crack.html 我的个人博客:https://www.tecchen.xyz,博文同步发布到博客园. 由于精力有限,对文章 ...
- np.array()和np.mat()区别
1. 生成数组所需格式不同 mat可以从字符串或列表中生成:array只能从列表中生成 2. 生成的数组计算方式不同 array生成数组,用np.dot()表示矩阵乘积,(*)号或np.multipl ...
- [转] String to Date conversion in hive - 在 Hive 中各种字符串转换成日期格式
[From] http://bigdataprogrammers.com/string-date-conversion-hive/ Please refer below table to conver ...
- C#控制台画图形
static void Main(string[] args) { //九九乘法 Console.WriteLine("九九乘法口诀"); ; i <= ; i++) { ; ...