Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤), the number of students who look for their course lists, and K (≤), the total number of courses. Then the student name lists are given for the courses (numbered from 1 to K) in the following format: for each course i, first the course index i and the number of registered students N​i​​ (≤) are given in a line. Then in the next line, N​i​​ student names are given. A student name consists of 3 capital English letters plus a one-digit number. Finally the last line contains the N names of students who come for a query. All the names and numbers in a line are separated by a space.

Output Specification:

For each test case, print your results in N lines. Each line corresponds to one student, in the following format: first print the student's name, then the total number of registered courses of that student, and finally the indices of the courses in increasing order. The query results must be printed in the same order as input. All the data in a line must be separated by a space, with no extra space at the end of the line.

Sample Input:

  1. 11 5
  2. 4 7
  3. BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
  4. 1 4
  5. ANN0 BOB5 JAY9 LOR6
  6. 2 7
  7. ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
  8. 3 1
  9. BOB5
  10. 5 9
  11. AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
  12. ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9

Sample Output:

  1. ZOE1 2 4 5
  2. ANN0 3 1 2 5
  3. BOB5 5 1 2 3 4 5
  4. JOE4 1 2
  5. JAY9 4 1 2 4 5
  6. FRA8 3 2 4 5
  7. DON2 2 4 5
  8. AMY7 1 5
  9. KAT3 3 2 4 5
  10. LOR6 4 1 2 4 5
  11. NON9 0
  12.  
  13. 题目分析:利用 map<string, set<int> >最后一个测试点超时了
    网上说自己写一个hash可以过
  14.  
  15. 超时代码
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <climits>
  3. #include<iostream>
  4. #include<vector>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<stack>
  9. #include<algorithm>
  10. #include<string>
  11. #include<cmath>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. map<string, set<int> >S;
  17. int N, K;
  18. string s;
  19. cin >> N >> K;
  20. for (int i = ; i < K; i++)
  21. {
  22. int j, M;
  23. cin >> j >> M;
  24. for (int k = ; k < M; k++)
  25. {
  26. cin >> s;
  27. S[s].insert(j);
  28. }
  29. }
  30. for (int i = ; i < N; i++)
  31. {
  32. cin >> s;
  33. cout << s << " " << S[s].size();
  34. for (auto it : S[s])
  35. cout << " " << it;
  36. cout << endl;
  37. }
  38. }

正确代码

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <climits>
  3. #include<iostream>
  4. #include<vector>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<stack>
  9. #include<algorithm>
  10. #include<string>
  11. #include<cmath>
  12. using namespace std;
  13. set<int> S[];
  14. int hashF(string s)
  15. {
  16. int num = ;
  17. for (int i = ; i < ; i++)
  18. num = num * + s[i] - 'A';
  19. num = num * + s[] - '';
  20. return num;
  21. }
  22. int main()
  23. {
  24. int N, K;
  25. string s;
  26. cin >> N >> K;
  27. for (int i = ; i < K; i++)
  28. {
  29. int j, M;
  30. cin >> j >> M;
  31. for (int k = ; k < M; k++)
  32. {
  33. cin >> s;
  34. S[hashF(s)].insert(j);
  35. }
  36. }
  37. for (int i = ; i < N; i++)
  38. {
  39. cin >> s;
  40. cout << s << " " << S[hashF(s)].size();
  41. for (auto it : S[hashF(s)])
  42. cout << " " << it;
  43. cout << endl;
  44. }
  45. }

1039 Course List for Student (25分)的更多相关文章

  1. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  2. PAT 1039 Course List for Student (25分) 使用map<string, vector<int>>

    题目 Zhejiang University has 40000 students and provides 2500 courses. Now given the student name list ...

  3. 【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)

    题意: 输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量.接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID.最后 ...

  4. 1039. Course List for Student (25)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1039 题目: 1039. Course List for Student (25) 时间限制 2 ...

  5. PAT甲题题解-1039. Course List for Student (25)-建立映射+vector

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789157.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  6. PAT (Advanced Level) 1039. Course List for Student (25)

    map会超时,二分吧... #include<iostream> #include<cstring> #include<cmath> #include<alg ...

  7. A1039 Course List for Student (25 分)

    一.技术总结 这里由于复杂度的限制,只能够使用vector,然后进行字符串转化:考虑到string.cin.cout会超时,可以使⽤用hash(262626*10+10)将学⽣生姓名变为int型,然后 ...

  8. PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)

    1047 Student List for Course (25 分)   Zhejiang University has 40,000 students and provides 2,500 cou ...

  9. PAT 1039 Course List for Student[难]

    1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 courses ...

随机推荐

  1. 纯C 实现 strpos substr strspilt str_trim

    在C 语言中没有C++ 好用的 spilt 方法 (STL 带的也不怎么好用) #include <stdio.h> #include <string.h> #include ...

  2. redis 出现(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details

    如果在ubuntu安装的redis含端口使用,但是某些时候常常出现 (error) MISCONF Redis is configured to save RDB snapshots, but is ...

  3. Linux系统是什么?亲身自学经历分享

    我是数字媒体专业学生,第一次接触LINUX的时候,是大一C语言课程里看到的,书上讲了C语言的发展历史.说到C语言的起源,就离不开UNIX系统.在20世纪60年代,贝尔实验室的研究员Ken Thomps ...

  4. H5页面,输入框的光标,如果页面上下滑动光标停留在页面上,除了输入框外,松手过了一段时间才跑回输入框里面

    有点类似这种情况 其中一个博主描述得比较详细,主要还有图 我是直接在App.vue主文件那里添加一下代码,主要是添加一个监听器,如果touchmove的时候就会触发让其失焦,就会消失那个光标,需要再次 ...

  5. Github Pages访问太慢?通过Netlify免费加速

    github pages vs netlify Github Pages为Github提供的一项静态站点托管服务,它直接从Github仓库获取静态文件进行发布,然后提供一个github.io的二级域名 ...

  6. 大数据安装之Kafka(用于实时处理的消息队列)

    一.安装部署kafka 1.集群规划 hadoop102                                 hadoop103                          hado ...

  7. Python Django撸个WebSSH操作Kubernetes Pod(下)- 终端窗口自适应Resize

    追求完美不服输的我,一直在与各种问题斗争的路上痛并快乐着 上一篇文章Django实现WebSSH操作Kubernetes Pod最后留了个问题没有解决,那就是terminal内容窗口的大小没有办法调整 ...

  8. Beef xss神器

    KALI中启动BEEFXSS PAYLOAD为 <script src=”http://攻击机IP:3000/hook.js”></script> 将攻击代码插入到存储型XSS ...

  9. 动态规划-Minimum Distance to Type a Word Using Two Fingers

    2020-01-12 18:28:13 问题描述: 问题求解: 本题还是非常困难的,至少我在看到这个题目的时候是没有想到怎么解决的.我当时联想到的题目是那条grid走两遍的题目,那条题目也很麻烦,使用 ...

  10. Falling Squares

    2020-01-08 10:16:37 一.Falling squares 问题描述: 问题求解: 本题其实也是一条经典的区间问题,对于区间问题,往往可以使用map来进行区间的维护操作. class ...