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:

11 5
4 7
BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
1 4
ANN0 BOB5 JAY9 LOR6
2 7
ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
3 1
BOB5
5 9
AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9

Sample Output:

ZOE1 2 4 5
ANN0 3 1 2 5
BOB5 5 1 2 3 4 5
JOE4 1 2
JAY9 4 1 2 4 5
FRA8 3 2 4 5
DON2 2 4 5
AMY7 1 5
KAT3 3 2 4 5
LOR6 4 1 2 4 5
NON9 0
题目分析:利用 map<string, set<int> >最后一个测试点超时了
网上说自己写一个hash可以过 超时代码
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std; int main()
{
map<string, set<int> >S;
int N, K;
string s;
cin >> N >> K;
for (int i = ; i < K; i++)
{
int j, M;
cin >> j >> M;
for (int k = ; k < M; k++)
{
cin >> s;
S[s].insert(j);
}
}
for (int i = ; i < N; i++)
{
cin >> s;
cout << s << " " << S[s].size();
for (auto it : S[s])
cout << " " << it;
cout << endl;
}
}

正确代码

 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
set<int> S[];
int hashF(string s)
{
int num = ;
for (int i = ; i < ; i++)
num = num * + s[i] - 'A';
num = num * + s[] - '';
return num;
}
int main()
{
int N, K;
string s;
cin >> N >> K;
for (int i = ; i < K; i++)
{
int j, M;
cin >> j >> M;
for (int k = ; k < M; k++)
{
cin >> s;
S[hashF(s)].insert(j);
}
}
for (int i = ; i < N; i++)
{
cin >> s;
cout << s << " " << S[hashF(s)].size();
for (auto it : S[hashF(s)])
cout << " " << it;
cout << endl;
}
}

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. VS2017配置opencv-4.2.0详细步骤

    VS2017配置opencv-4.2.0详细步骤   1.下载opencv的安装包并解压.下载网址https://sourceforge.net/projects/opencvlibrary/ 图1 ...

  2. zabbix基本概述

    #zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案 #官网地址 #官方网站 http://www.zabbix.com #zabbix4.2 ...

  3. 编译putty 源码去掉 Are you sure you want to close this session? 提示

    0, 为什么要编译 putty ?在关闭窗口的时候,会弹出一个 Are you sure you want to close this session?要把这个去掉.当然也可以用 OD 之类的来修改. ...

  4. PHP把图片存入数据库(非路径)【待测试】

    大部分人的图片上传都是保存一个路径到数据库,这样在插入时确实快,也符合web的特点,但是在删除时就很麻烦,需要找到文件并删除,该代码能够把代码直接存入数据库,删除时一并删除.请注意:这样的话数据库大小 ...

  5. php里面的一些面试经典的函数

    <?php /* 这是一个多线程的读取解决的函数 @param1 $fle 传入要读取的文件名 */ function filelock($fle){ $fp=fopen($fls,'w+'); ...

  6. 结巴分词demo

    #encoding=utf-8 from __future__ import unicode_literals import sys sys.path.append("../") ...

  7. mongo请求超时

    no_cursor_timeout=True参数的使用 实例: import pymongo handler = pymongo.MongoClient().db.col with handler.f ...

  8. Java 基础(六):循环

    循环 老生常谈的一个控制流程了,我们在是使用数组和集合的时候,遍历元素的时候经常会用到循环的结构,Java具有非常灵活的三种循环机制: 根据是否知道循环的次数可以为分为while循环,do...whi ...

  9. 微信小程序开发(二)认识开发工具

    腾讯微信团队提供非常优秀的微信小程序开发工具,大大降低了开发者的入门门槛,为他们点赞!上一篇文章已经说明了,如何注册及下载开发工具,现在我们就来一起认识见识一下开发工具的庐山真面目. 首次打开这个开发 ...

  10. [Alg] 文本匹配-单模匹配-KMP

    1. 暴力求解 如下图所示.蓝色的小三角表示和sequence比较时的开始字符,绿色小三角表示失败后模式串比对的开始字符,红色框表示当前比较的字符对. 当和模式串发生不匹配时,蓝色小三角后移一位,绿色 ...