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行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...
随机推荐
- B1818 [Cqoi2010]内部白点 树状数组
这个题的想法很好想,就是进行排序之后直接检查每个点的上下左右是否有黑点就行.但是直接枚举显然不行,那怎么办呢?我们就用树状数组维护扫描线,把每排左右点看成一条线覆盖,然后从下往上扫,遇到下加一,遇到上 ...
- MyBatis高级查询 一对一映射
drop database if exists simple; create database simple; use simple; drop table if exists sys_user; c ...
- MAC地址 初识
MAC地址 即物理地址/硬件地址 地址长度为48位,6字节. 格式为:00-23-5A-15-99-42 一个网卡对应一个MAC地址(比如笔记本,有线网卡有一个MAC地址,无线网卡也有一个MAC地址) ...
- 《Akka应用模式:分布式应用程序设计实践指南》读书笔记9
性能 这也是一个比较大的问题,因为性能不一定是Akka本身的问题,还可能是你代码写的有问题. 优化的第一步就是找出性能的瓶颈,隔离出应用程序里面比较耗时的部分,然后尝试对其优化,减少需要耗费的时间成本 ...
- Android Studio 常用快捷键(超实用!!!)
快捷键又称为“热键”,多个按键的组合可以实现某些快速操作,例如Window中最常用的Ctrl+C和Ctrl+V,熟练使用快捷键可以大大提高开发效率并可以减少某些错误的发生.Android Studio ...
- $tsinsenA1067$
\(problem\) 这种题目需要一个定理 \(a[1]+a[2]+a[3]+a[4]...=(a[1]%mod)+...\) 本人出奇的懒 然后 动态规划?(恰似枚举) #include < ...
- UE4源码版食用要记
UE4源码版和预编译版不能共享工程,这和插件版是一样的. 一般来说我都是在VS中生成编辑器,于编辑器中添加新类,VS中编辑代码. 编译引擎的时候编译配置使用的是devepolmenteditor.开发 ...
- SVN异常处理(五)-状态小图标不见了
1.发现问题 装了Win10,再装了Office2016等一些最新软件后,发现SVN状态小图标竟然就不见了 2.分析问题 在Window系统中,当UAC启动时,有些应用程序的图标上会显示一个盾牌,像这 ...
- node 搭建本地服务器
/** * 代理服务器 natapp -authtoken f1bdaa0535788971 * 热部署指令 supervisor index */ const Koa = require('koa' ...
- 【PostgreSQL-9.6.3】分区表
PostgreSQL中的分区表是通过表继承来实现的(表继承博客http://www.cnblogs.com/NextAction/p/7366607.html).创建分区表的步骤如下: (1)创建“父 ...