PAT 1047. Student List for Course
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=40000), the total number of students, and K (<=2500), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (<=20) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.
Output Specification:
For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.
Sample Input:
10 5
ZOE1 2 4 5
ANN0 3 5 2 1
BOB5 5 3 4 2 1 5
JOE4 1 2
JAY9 4 1 2 5 4
FRA8 3 4 2 5
DON2 2 4 5
AMY7 1 5
KAT3 3 5 4 2
LOR6 4 2 4 1 5
Sample Output:
1 4
ANN0
BOB5
JAY9
LOR6
2 7
ANN0
BOB5
FRA8
JAY9
JOE4
KAT3
LOR6
3 1
BOB5
4 7
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
5 9
AMY7
ANN0
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
分析
起先用set做的,最后一个点超时了。
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
char name[40008][5];
vector<int> courses[2508];
bool cmp(int a,int b){
return strcmp(name[a],name[b])<0;
}
int main(){
int n,k,cnt,course;
cin>>n>>k;
for(int i=1;i<=n;i++){
scanf("%s %d",name[i],&cnt);
for(int j=1;j<=cnt;j++){
scanf("%d",&course);
courses[course].push_back(i);
}
}
for(int i=1;i<=k;i++){
printf("%d %d\n",i,courses[i].size());
sort(courses[i].begin(),courses[i].end(),cmp);
for(int j=0;j<courses[i].size();j++)
printf("%s\n",name[courses[i][j]]);
}
return 0;
}
PAT 1047. Student List for Course的更多相关文章
- PAT 1047 Student List for Course[一般]
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- 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 ...
- 1047 Student List for Course ——PAT甲级真题
1047 Student List for Course Zhejiang University has 40,000 students and provides 2,500 courses. Now ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT 甲级 1047 Student List for Course
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 Zhejiang University ha ...
- PAT (Advanced Level) 1047. Student List for Course (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲级题解-1047. Student List for Course (25)-排序
一开始是建立了course[2501][40001]数组,存储每节课的学生编号然后for循环两层输出,但这样复杂度为O(2500*40000),也很明显导致最后时间超时后来发现最多40000学生,每个 ...
- 【PAT甲级】1047 Student List for Course (25 分)
题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...
随机推荐
- 文章编辑器 文本替换 操作dom 发帖 富文本 今日头条发布富文本的实现 键盘化的html
js 修改 iframe it=document.getElementById('ueditor_0').contentWindow.document.getElementsByTagName(& ...
- git的基本操作流程
1.git clone 初始会有默认的master分支,并且master和origin/master自动建立了映射关系 2. git checkout -b local 创建并且切换到local ...
- YTU 2795: 编程题AB-侦察员的密码
2795: 编程题AB-侦察员的密码 时间限制: 1 Sec 内存限制: 128 MB 提交: 155 解决: 43 题目描述 侦察员小甲在被捕前在墙上写了两行文字(ASCII字符),其中包含了他 ...
- cmd 命令操纵文件管理器、创建(删除)多级文件夹
命令行打开文件夹窗口的六种方法 1. 使用 start 命令 # 打开指定文件夹 > start 路径 # 打开当前文件夹 > start . # 打开含空格文件夹 > start ...
- bzoj1951 [Sdoi2010]古代猪文 ——数论综合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1951 题意就是要求 G^( ∑(k|n) C(n,k) ) % p,用费马小定理处理指数,卢 ...
- bzoj1018
线段树分治+并查集 线段树本身就是分治结构,碰见这种带删除修改的题目是再合适不过的,我们对于每段修改区间在线段树上打标记,每次路过就进行修改,叶子结点表及答案,先把所有修改在线段树上标记,然后dfs就 ...
- SQL service
依赖关系解决 ============================================================================================= ...
- createrepo -g /enp/comps.xml .
cd /enp; createrepo -g /enp/comps.xml .
- BZOJ 3456 NTT图的计数 容斥
思路: RT 懒得写了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...
- 【USACO2002 Feb】奶牛自行车队
[USACO2002 Feb]奶牛自行车队 Time Limit: 1000 ms Memory Limit: 131072 KBytes Description N 头奶牛组队参加自行车赛.车队在比 ...