PAT(甲级)1047
来源:互联网 发布:怎样写淘宝客招募 编辑:程序博客网 时间:2024/05/18 22:44
1047. Student List for Course (25)
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 5ZOE1 2 4 5ANN0 3 5 2 1BOB5 5 3 4 2 1 5JOE4 1 2JAY9 4 1 2 5 4FRA8 3 4 2 5DON2 2 4 5AMY7 1 5KAT3 3 5 4 2LOR6 4 2 4 1 5Sample Output:
1 4ANN0BOB5JAY9LOR62 7ANN0BOB5FRA8JAY9JOE4KAT3LOR63 1BOB54 7BOB5DON2FRA8JAY9KAT3LOR6ZOE15 9AMY7ANN0BOB5DON2FRA8JAY9KAT3LOR6ZOE1
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#define SQUARE 676#define CUBE 17576///////////////////////////////////////////////////can use vector <string> and sort them automatically////////////////////////////////////////////////////using namespace std;vector<int> s;const int gap=456976;int convert(char *str){int res = (((str[0]-'A')*26+(str[1]-'A'))*26 +(str[2]-'A'))*26+str[3]-'0';return res;}void recover(int n){char str[5];int n2=n/SQUARE;int n3=n%SQUARE;str[0] = 'A'+n2/26;str[1] = 'A' + n2%26;str[2] = 'A' + n3/26;str[3] = '0'+ n3%26;str[4] = '\0';printf("%s\n",str);}int find(int value){int high = s.size()-1;int low=0;int mid;while(low <=high){mid = (low+high)/2;if(s[mid] > value) high = mid-1;else if(s[mid] == value) return mid;else low = mid+1; }return low;}int main(){int N,K;char str[8];int num,value,index,tmp;scanf("%d%d",&N,&K);getchar();for(int i=0;i<N;i++){scanf("%s%d",str,&num);value = convert(str);for(int j=0;j<num;j++){scanf("%d",&index);tmp = 0;for(int k =0;k<index;k++) tmp += gap;s.push_back(value+tmp);}} sort(s.begin(),s.end());//printf("%d\t%d",s.back(),(N+1)*456976);s.push_back((K+1)*gap); //take care,N represents the number of student, while K indicates the number ofvalue = 0; //courses!!!!for(int i=1;i<=K;i++){value += gap; int j = find(value); //the index equal or just bigger than value int k = find(value+gap);printf("%d %d\n",i,k-j); for(;j<k;j++) recover(s[j]-value);}return 0;}
- PAT(甲级)1047
- 浙大PAT甲级 1047
- PAT甲级1047
- PAT 甲级
- 从PAT甲级1047题说开去
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- jQuery全选功能
- python学习(一):环境安装及HelloWorld
- 机房收费系统开发进度月报
- 源码编译安装runc碰到的一个小坑
- Filter实现登录功能限制
- PAT(甲级)1047
- 安卓Button控件OnClickListener的三种实现方式
- C语言复习day2
- PAT(甲级)1048
- WPF 中图标路径问题
- jqery实现10X10的表格,双击消失
- 停课的沉淀反思(四)——任道重远
- poj 1222
- 自定义的RPC的Java实现