本来用map 写的,死活超时,看来卡不过去
只能哈希了
这里还稍微优化了一下,其实每个 哈希后的值存个 vector 来表示他的原值也行
(注: 博客作为交流使用,请勿抄袭应付作业)
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 100000 + 7, INF = 0x7f7f7f7f;
int n, m, v, id, cnt = 0;
char s[27];
struct node {
char s[27];
int ans, next;
node() { ans = 0; }
}a[maxn];
int head[maxn];
int get_id(char s[]) {
int id = 0;
for(int i = 0; i < 17; ++i) {
id = 10 * id + (s[i] - '0');
id %= maxn;
//cout << " --- " << endl;
}
if(s[17] == 'x') id = 10 * id + 10;
else id = 10 * id + (s[17] - '0');
id %= maxn;
return id;
}
void add(int id, char s[], int v) {
int f = 0;
for(int i = head[id]; i !

博主分享了一篇关于使用哈希方法解决PTA航空公司的VIP客户查询问题的博客,原本尝试使用map实现但遇到超时问题,通过优化哈希实现提高效率。文中提到可以将哈希后的值存储为vector来保存原值。博客提醒读者仅供交流,不可用于抄袭应付作业。
最低0.47元/天 解锁文章
6986





