题意:

思路:

读完题目之后的第一思路就是用map将客户的id(string类型)与里程road(int类型)形成映射,然后直接用id查找添加里程或输出里程。但是400ms的限制妥妥的超时了。然后意识到要用哈希做,但是用哈希就有一点不好解决,每个客户的里程怎么保存,考虑了很长时间无果,搜了一下博客,发现可以用结构体来保存,平常用数组模拟链表的时候都是直接开的一维数组,所以当每个客户的信息多了后就没有结构体来的理解方便了。

第一次尝试:这个题N的上限是1e5,所以将每个客户的id转换成long long类型,然后对1e5+7取余,结果作为下标对应到数组里边存里程,完美过样例,提交果断WA。。。。。。。

第二次尝试:又看了一遍题目,思考了一下,哈希会出现冲突,需要处理冲突。所以数组模拟链表处理冲突,提交AC。

代码:

 #include <iostream>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define FRE() freopen("in.txt","r",stdin) using namespace std;
typedef long long ll;
typedef pair<int,string> P;
const int maxn = 1e5+;
int head[maxn];
struct Peo{
char name[];
int road;
int next;
}p[maxn];
int cnt = ; int GetId(char* str) {
ll res = ;
for(int i = ; i<strlen(str); i++) {
if(isdigit(str[i])) {
res = res* + str[i]-'';
} else {
res = res* + ;
}
}
return (int)(res%maxn);
} void Add_Node(char* str,int id,int temp){
bool ok = true;
for(int i = head[id]; ~i; i = p[i].next){
if(strcmp(str,p[i].name) == ){
p[i].road += temp;
ok = false;
}
}
if(ok){
int i = ;
p[cnt].road += temp;
for(i = ; str[i]; i++){
p[cnt].name[i] = str[i];
}
p[cnt].name[i] = '\0';
p[cnt].next = head[id];
head[id] = cnt++;
}
return;
} bool ToFind(char* str,int id){
for(int i = head[id]; i!=-; i = p[i].next){
if(strcmp(str, p[i].name) == ){
cout<<p[i].road<<endl;
return true;
}
}
return false;
} int main() {
char str[];
int n,k,temp;
cin>>n>>k;
memset(head,-,sizeof(head));
for(int i = ; i<n; i++) {
cin>>str>>temp;
if(temp<k) temp = k;
int index = GetId(str);
Add_Node(str,index,temp);
}
int m;
cin>>m;
for(int i = ; i<m; i++) {
cin>>str;
int index = GetId(str);
if(!ToFind(str,index)){
printf("No Info\n");
}
}
return ;
}

7-13 航空公司VIP客户查询 (25 分)的更多相关文章

  1. 5-45 航空公司VIP客户查询 (25分) HASH

    不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务.现给定某航空公司全体会员的飞行记录,要求实现根据身份证号码快速查询会员里程积分 ...

  2. 12. The Biggest Safety Threat Facing Airlines 航空公司面临的最大安全威胁

    12. The Biggest Safety Threat Facing Airlines 航空公司面临的最大安全威胁 (1) The biggest safety threat facing air ...

  3. 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)

    01-复杂度2 Maximum Subsequence Sum   (25分) Given a sequence of K integers { N​1​​,N​2​​, ..., N​K​​ }. ...

  4. L2-001 紧急救援 (25 分)

    L2-001 紧急救援 (25 分)   作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快 ...

  5. 1125 Chain the Ropes (25 分)

    1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...

  6. 1122 Hamiltonian Cycle (25 分)

    1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...

  7. 1113 Integer Set Partition (25 分)

    1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...

  8. 1044 Shopping in Mars (25 分)

    1044 Shopping in Mars (25 分) Shopping in Mars is quite a different experience. The Mars people pay b ...

  9. 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...

随机推荐

  1. hdu 4549 M斐波那契数列(矩阵高速幂,高速幂降幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=4549 f[0] = a^1*b^0%p,f[1] = a^0*b^1%p,f[2] = a^1*b^1%p... ...

  2. Hackerrank Connected Cell in a Grid

    Problem Statement You are given a matrix with m rows and n columns of cells, each of which contains ...

  3. BZOJ 2338 HNOI2011 数矩形 计算几何

    题目大意:给定n个点,求一个最大的矩形,该矩形的四个顶点在给定的点上 找矩形的方法是记录全部线段 若两条线段长度相等且中点重合 这两条线段就能够成为矩形的对角线 于是我们找到全部n*(n-1)/2条线 ...

  4. 用R语言完成的交通可视化报告

    http://sztocc.sztb.gov.cn/roadcongmore.aspx最终实现这几个图:1. 实时道路交通可视化2. 实时道路拥堵排名3. 历史路况时间序列图4. 每日每小时道况热力图 ...

  5. python 文档生成 字符串替换

    替换 fnr, fnr_source, fnw = 'my.py.html', '产品清单.txt', 'my.py.res.html'd_source = {}with open(fnr_sourc ...

  6. Android 信息提示——Toast方式

    Toast用于向用户显示一些帮助/提示.一下列举了5中样式. 一.默认的效果(显示在屏幕的底部) 代码: Toast.makeText(getApplicationContext(), "默 ...

  7. SQL SERVER 语句大全

    ·SQL的简单查询实例教程关键词:SQL语句大全 中文网 整理编辑,经典SQL语句大全(SQL语句大总结),欢迎网友投稿 下列语句部分是Mssql语句,不可以在access中使用.SQL分类:DDL— ...

  8. bzoj2427 [HAOI2010]软件安装——缩点+树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2427 今天的考试题...好不容易一次写对了树形DP,却没发现有环的情况... 发现自己 ta ...

  9. PKUACM2018 A Wife——DP

    题目:http://poj.openjudge.cn/practice/C18A/ 据说正解是差分约束,转化的过程还要用到标准型.对偶型什么的知识,暂时还不太懂... 但也有贪心DP做法,有个结论:一 ...

  10. C. Unusual Product(cf)

    http://codeforces.com/problemset/problem/405/C 题意: 给出一个n*n的矩阵,有q个操作,输入3时,输出A ,A等于第i行乘以第i列的对应元素的和(mod ...