1039. Course List for Student (25)

时间限制
200 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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 (<=40000), the number of students who look for their course lists, and K (<=2500), 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 Ni (<= 200) are given in a line. Then in the next line, Ni 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会超时,只能手写一个hash
#include<map>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int maxn = 5e5 + 10;
int n, k, x, y, tot, M[maxn];
char s[maxn];
vector<int> t[maxn];int get(char *s)
{return (s[0] - 'A') * 6760 + (s[1] - 'A') * 260 + (s[2] - 'A') * 10 + s[3] - '0';
}int main()
{scanf("%d%d", &n, &k);for (int i = 1; i <= k; i++){scanf("%d%d", &x, &y);while (y--){scanf("%s", s);int k = get(s);if (!M[k]) M[k] = ++tot;t[M[k]].push_back(x);}}for (int i = 1; i <= tot; i++) sort(t[i].begin(), t[i].end());while (n--){scanf("%s", s);printf("%s", s);int k = M[get(s)];if (k){printf(" %d", t[k].size());for (int i = 0; i < t[k].size(); i++){printf(" %d", t[k][i]);}}else printf(" 0");printf("\n");}return 0;
}

PAT (Advanced Level) Practis 1039 Course List for Student (25)相关推荐

  1. 【PAT (Advanced Level) Practice】1086 Tree Traversals Again (25 分)

    众所周知只有前序遍历和后序遍历是不可能推出中序遍历的,所以我就不废话了 由树的前序遍历和中序遍历可以推后序遍历 由树的中序遍历和后序遍历可以推前序遍历 #include <cstdio> ...

  2. 【PAT (Advanced Level) Practice】1149 Dangerous Goods Packaging (25 分)

    1149 Dangerous Goods Packaging (25 分) When shipping goods with containers, we have to be careful not ...

  3. 【PAT (Advanced Level) Practice】1113 Integer Set Partition (25 分)

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  4. PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642 题目描述: A Binary Search Tr ...

  5. PAT (Advanced Level) Practice 题解代码 - II (1051-1100)

    PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...

  6. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  7. PAT (Advanced Level) Practice 题目集合(1001 ~ 1050)(正在更新)

    1001 A+B Format (20 分) 题目大意:计算a+b,结果按照西方的那种写数字的方式输出,从三个数一个逗号那种. #include<bits/stdc++.h> using ...

  8. 1039. Course List for Student (25)

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

  9. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

最新文章

  1. 创建三维建筑可视化和虚拟现实的最快和最简单的方法
  2. tcp/ip 协议栈Linux源码分析一 IPv4分片报文重组分析一
  3. 炒股如果亏损一直买入可行吗
  4. python可以做什么工作-济南大数据可以做哪些岗位
  5. mysql更新语句使用order by
  6. Oracle单实例数据库迁移到Oracle RAC 环境之(2)--实施篇
  7. eclipse使用配置教程
  8. npcap关闭_Npcap.资料
  9. 将网页转换成pdf文档的方法
  10. python修改xml文件内容,不废话,拿来即用
  11. Typora文档添加水印
  12. 小米商城项目api接口编写日志
  13. SDCC和Keil之stc89c52资料(纪念51单片机40周年)
  14. 在群晖上搭建基于 PostgreSQL 的 Joplin Server
  15. 申请邓白氏编码的流程
  16. 深读 | 《人人都是产品经理2.0》中篇
  17. 社保的计算及缴纳地及个人部分和公司缴纳部分的一些疑问
  18. 华为手机备忘录怎样设置每个月12号短信提醒要做的事
  19. Java常用的IO流
  20. 传统民俗闹新春 浙江千年古村飘“非遗年味”

热门文章

  1. 【mysql】关闭mysql缓存的方法
  2. mysql 启动和关闭
  3. 如何使用拟我表情做为用户的头像
  4. 查找:顺序查找、二分查找、分块查找
  5. 法规标准-ISO 22839标准解读(2013版)
  6. idea中好用的git shelve changes和stash changes
  7. 2000-2020年中国省份、282个地级市Dagum基尼系数及分解
  8. php5.6 php-fpm nginx安装和配置
  9. RSA算法以及所涉及的数论定理的简单证明
  10. C++20 coroutine 探索I:co_await 原理 | 使用 C++ 协程写 python generator