1039. Course List for Student (25)
来源:互联网 发布:dw做淘宝导航条 编辑:程序博客网 时间:2024/05/21 11:52
1039. Course List for Student (25)
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 54 7BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE11 4ANN0 BOB5 JAY9 LOR62 7ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR63 1BOB55 9AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9Sample Output:
ZOE1 2 4 5ANN0 3 1 2 5BOB5 5 1 2 3 4 5JOE4 1 2JAY9 4 1 2 4 5FRA8 3 2 4 5DON2 2 4 5AMY7 1 5KAT3 3 2 4 5LOR6 4 1 2 4 5NON9 0
显然在栈上空间是不够的,所以作为全局变量把存储的数组建在了堆上,但是最后一个测试用例老是过不了,显示内存超限,我想想,26*26*26*10*2500这样的最坏情况显然要超64MB的,也就是说估计测试用例也不会有这种学生数最大而且每个学生都选了2500节课这种极端情况,所以我就把course数组的大小从2500慢慢开小,事实证明也确实如此,开80最后一个用例就可以正确的过了。
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX 26*26*26*10int GetValue(char a[]){int value ;value = a[3] - '0' + 10*(a[2] -'A') + 10*26*(a[1]-'A') + 10*26*26*(a[0] - 'A');return value;}typedef struct students{int count;int course[80];}STUDENT;int cmp (const void * a,const void *b){return *(int*)a - *(int*)b;}STUDENT student[MAX];int main(){char a[5];int i,j,N,K,CourseID,CourseCount,value;//freopen("d:\\input.txt","r",stdin);scanf("%d%d",&N,&K);for(i=0;i<K;i++){scanf("%d%d",&CourseID,&CourseCount);for(j=0;j<CourseCount;j++){scanf("%s",a);value = GetValue(a);student[value].course[student[value].count] = CourseID;student[value].count++;}}for(i=0;i<N;i++){scanf("%s",a);value = GetValue(a);printf("%s",a);printf(" %d",student[value].count);qsort(student[value].course,student[value].count,sizeof(student[value].course[0]),cmp);for(j=0;j<student[value].count;j++){printf(" %d",student[value].course[j]);}puts("");}return 0;}
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)-PAT
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- Win7 X64下MASM5.0开发环境搭建及配置
- 极值与导数
- 静态化、伪静态、大型网站存在的问题
- 重载、覆盖和隐藏的区别
- java代码性能提高技巧之String.intern()
- 1039. Course List for Student (25)
- 杭电ACM----1001
- Eclipse tomcat插件使用
- Android统一风格 —— 主题
- 软件测试的分类
- XListView上拉刷新下拉加载
- 上拉,下拉布局2
- Ubuntu 中安装 Code::Blocks
- HTTP常见状态码