当前位置:网站首页>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;
}
边栏推荐
- Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL Web框架Gin(九)
- 合奥科技网络 面试(含参考答案)
- ReentrantLock工作原理
- cadence landscape bindkey
- Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
- "Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results
- 【LeetCode】94.二叉树的中序遍历
- MySQL8.0.28 installation tutorial
- 【LeetCode】144.二叉树的前序遍历
- 【LeetCode】1374. Generate a string with an odd number of each character
猜你喜欢
analog IC layout-Environmental noise
数仓:为什么说 ETL 的未来不是 ELT,而是 EL (T)
Flask之路由(app.route)详解
WebShell Feature Value Summary and Detection Tool
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
analog IC layout-Design for reliability
Chapter 10_Index Optimization and Query Optimization
MySQL8.0.28安装教程
MySQL index optimization in practice
Heuristic merge, DSU on Tree
随机推荐
详解最强分布式锁工具:Redisson
【Koltin Flow(三)】Flow操作符之中间操作符(一)
Invalid bound statement (not found)出现的原因和解决方法
【LeetCode】145.二叉树的后序遍历
WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use
svm.SVC应用实践1--乳腺癌检测
咨询cdc for oracle,增量同步scan.startup.mode只有initial和la
PHP WebSehll 后门脚本与检测工具
AcWing 1053. 修复DNA 题解(状态机DP、AC自动机)
架构:应用架构的演进以及微服务架构的落地实践
Curriculum Vitae;CV
微服务:微智能在软件系统的简述
亲身经历过的面试题
pyqt上手体验
【CNN记录】tensorflow slice和strided_slice
有人知道HTML怎么到MYSQL数据库吗? (NODEJS)
analog IC layout
isa指针使用详情
JSP Webshell free kill
剑指 Offer 14- I. 剪绳子