当前位置:网站首页>7-43 字符串关键字的散列映射 (25 分) 谜之测试点
7-43 字符串关键字的散列映射 (25 分) 谜之测试点
2022-08-02 02:56:00 【兄dei!】
原题:https://pintia.cn/problem-sets/15/problems/890
| 0 | sample 1 无冲突 | 答案正确 | 6 | 4 ms | 452 KB |
| 1 | sample 2 有冲突 | 答案正确 | 8 | 5 ms | 320 KB |
| 2 | 有重复关键字 | 答案正确 | 3 | 5 ms | 448 KB |
| 3 | 最大和最小字符串,以及不足3位的字符串 | 答案错误 | 0 | 5 ms | 324 KB |
| 4 | 最大N,随机 | 答案正确 | 5 | 6 ms | 324 KB |
整了半天,也调试了许多例子,愣是没发现哪里错了。。
暂且搁着,等有缘人相助。。
#include<iostream>
#include<string>
#include<math.h>
#include<map>
using namespace std;
map <string, int> mp;
int vis[1010];
int ch(char op) { return op - 'A'; }
int main()
{
int n, p;
cin >> n >> p;
string s;
for (int i = 0; i < n; i++)
{
cin >> s;
if (mp.count(s))//如果这个名字用过了
{
if (i > 0)cout << " ";
cout << mp[s];
continue;
}
int nums = 0;
int len = s.size()-1;
//这里明明处理了小于三位的字符串啊。怎么就是过不了
if (len == 0)nums = ch(s[0]);
else if (len == 1)nums = ch(s[0]) * 32 + ch(s[1]);
else nums = ch(s[len - 2]) * 32 * 32 + ch(s[len - 1]) * 32 + ch(s[len]);
nums = nums % p;
int I = nums, info = 1,t=1;
while (vis[I] == 1 )//当位置有人占着,平方探测法
{
I = (nums + info) % p;
info = -info;
if (info > 0)
{
t++;
info = t*t;
}
}
vis[I] = 1;
mp[s] = I;
if (i != 0)cout << " ";
cout << mp[s];
}
return 0;
}边栏推荐
- Docker-compose安装mysql
- 【LeetCode】94.二叉树的中序遍历
- node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module ‘./scope‘
- 1. 获取数据-requests.get()
- 最大层内元素和
- Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
- Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
- 第 304 场力扣周赛
- IPFS deployment and file upload (golang)
- ReentrantLock工作原理
猜你喜欢
随机推荐
WebShell连接工具(中国菜刀、WeBaCoo、Weevely)使用
Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
(一)Redis: 基于 Key-Value 的存储系统
【LeetCode】1374. 生成每种字符都是奇数个的字符串
PAT甲级打卡-1001-1004
【LeetCode】104.二叉树的最大深度
Chapter 10_Index Optimization and Query Optimization
【LeetCode】83.删除排序链表中的重复元素
mysql8.0.28 download and installation detailed tutorial, suitable for win11
node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module ‘./scope‘
PHP WebSehll 后门脚本与检测工具
Nacos source code analysis topic (1) - environment preparation
【LeetCode】206. Reverse linked list
AcWing 1053. Repair DNA problem solution (state machine DP, AC automata)
mysql8.0.28下载和安装详细教程,适配win11
feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
7、MySQL Workbench 导出导入数据库
2W字!梳理50道经典计算机网络面试题(收藏版)
WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use
请教各位大佬,如果我代码里面设置了,这个id我在什么地方可以查到呢?连接到mysql cluste








