1039. Course List for Student (25)

来源:互联网 发布:教师网络培训服务平台 编辑:程序博客网 时间:2024/06/06 01:02

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 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 NON9
Sample 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
用map和vector 充当数组邻接表的最后一个测试点运行超时,然后就用大数组了;还看到另一个通过数据范围和课程编号的Hash的,这个就直接贴别人的了,其实还有的没有完全理解好,那个id应该是默认开始为零吧,等有时间重新弄弄看,没有初始化总觉得乖乖的,那个异或48的好像是通过ASCII码直接取,相当于char-‘0’;。三个都在后面
2015-8-6  19:57理顺了Hash的

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月06日 13:23答案正确251039C++ (g++ 4.7.2)8510924datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确3442015/151答案正确344042/22答案正确344682/23答案正确344042/24答案正确344802/25答案正确85109242/2
#include<iostream>   #include<vector>#include<string>#include<algorithm>using namespace std; bool Cmpcourse(const int&A, const int&B){ return A < B; }#define MAX 26*26*26*10int indexreturn (char*name){  return (((name[0] - 'A') * 26 + name[1] - 'A') * 26 + name[2] - 'A') * 10 + name[3] - '0';}int main(){  vector<vector<int> >studentGmap(MAX);/*这个vector是用括号的*/  int N, K,course,num,index;  char name[5];  scanf("%d%d", &N, &K);  while (K--)  {    scanf("%d%d",&course,&num);     while (num--)    {      scanf("%s",name);        studentGmap[indexreturn(name)].push_back(course);    }  }  while (N--)  {    scanf("%s", name);    index = indexreturn(name);    K = studentGmap[index].size();    printf("%s %d",name,K);    sort(studentGmap[index].begin(), studentGmap[index].end(), Cmpcourse);    for (course=0; course<K; course++)      printf(" %d", studentGmap[index][course]);    printf("\n");  }  system("pause");  return 0;}

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月06日 19:55答案正确251039C++ (g++ 4.7.2)973892datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确2304415/151答案正确228682/22答案正确228682/23答案正确228682/24答案正确228682/25答案正确9738922/2
#include<iostream> #include<string>  #include<algorithm> using namespace std;int nameToindex(char *name) {  return (name[0]-'A')*26*260+(name[1]-'A')*260+(name[2]-'A')*10+name[3]-'0';}bool HashCMP(const int&A,const int &B){return A<B;}int binaryFind(int key,int Start,int End,int *studentHash){  int mid;  while(Start<=End)  {    mid=(Start+End)/2;    if(studentHash[mid]>key) End=mid-1;     else Start=mid+1;  }  return End;}int main(){    int studentHash[2500*200]={0};  int studentIndex[26*26*26*10]={0};  int N, K, course, num,index,different,identity;  char name[5];  scanf("%d%d",&N,&K);  different=1;  identity=0;  while (K--)  {    scanf("%d%d",&course,&num);     while (num--)    {       scanf("%s",name);      index=nameToindex(name);      if(0==studentIndex[index])              studentIndex[index]=different++;/*这里根据每个名字第一次进入进行划分,第一个1,第二个2,……                              *那么下面studentHash[i]的值只要范围在[2501,5000]属于第一个的                                                 范围在[5001,7500]属于第二个的                                   以此递增*/          studentHash[identity++]=studentIndex[index]*2500+course;    }  }  sort(studentHash,studentHash+identity,HashCMP);  while (N--)  {     scanf("%s",name);       different=studentIndex[nameToindex(name)];        if(0==different)        printf("%s 0\n",name);      else    {        index=binaryFind(different*2500,0,identity-1,studentHash);/*获得的是小于或等于different*2500的,那么接下去的是[different*2500+1,(different+1)*2500]中最小的*/           num=binaryFind((different+1)*2500,index,identity-1,studentHash);/*获得的是小于或等于(different+1)*2500的*/       printf("%s %d",name,num-index);         for(index++;index<=num;index++)         printf(" %d",studentHash[index]-different*2500);          printf("\n");     }  }  system("pause");  return 0;}

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月06日 16:50答案正确251039C++ (g++ 4.7.2)783840datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确130815/151答案正确13042/22答案正确13082/23答案正确11802/24答案正确11802/25答案正确7838402/2

#include <stdio.h>#include <map>#include <set>#include <string.h>#include <string>#include <algorithm>#include <vector>using namespace std;bool get(int& a){  if( scanf("%d",&a) == EOF ) return false ;  return true ;}const int maxn = 2500*200 ;int nimei[maxn] , cnt ;int id[26][26][26][10] ;int bs(int key,int l,int r){  int mid ;  while ( l <= r )  {    mid = ( l + r ) >> 1 ;    if( nimei[mid] > key )      r = mid - 1 ;    else      l = mid + 1 ;  }  return r ;}int main(){  int n , m ;  get(n); get(m);  int i , j , k ;  int idCnt = 1 ;  cnt = 0 ;  for ( i = 0 ; i < m ; i++)  {    get(j); get(k);    char str[16] ;    while(k--)    {      scanf("%s",str);      int &temp = id[str[0]-'A'][str[1]-'A'][str[2]-'A'][str[3]^48] ;      if( temp == 0 )        temp = idCnt++;      nimei[cnt++] = temp*2500+j ;    }  }  sort(nimei,nimei+cnt);  char name[16] ;  while(n--)  {    scanf("%s",name);    int t = id[name[0]-'A'][name[1]-'A'][name[2]-'A'][name[3]^48] ;    if( t == 0 )    {      printf("%s 0\n",name);      continue;    }    j = bs(t*2500,0,cnt-1) ;    k = bs((t+1)*2500,j,cnt-1);    printf("%s %d",name,k-j);    for ( j++; j <= k ; j++)    {      printf(" %d",nimei[j]-t*2500);    }    puts("");  }  return 0;}

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月06日 10:56部分正确231039C++ (g++ 4.7.2)1384datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确130815/151答案正确13042/22答案正确12642/23答案正确11802/24答案正确13842/25运行超时  0/2
#include<iostream> #include<string> #include<map> #include<vector>#include<algorithm>using namespace std; bool Cmpcourse(const int&A, const int&B){ return A < B; }int main(){  map<string, vector<int>>studentGmap;  int N, K,course,num;  string name;  cin >> N >> K;  while (K--)  {    cin >> course >> num;    while (num--)    {      cin >> name;      studentGmap[name].push_back(course);    }  }  while (N--)  {    cin >> name;    cout << name << " " << studentGmap[name].size();    sort(studentGmap[name].begin(), studentGmap[name].end(), Cmpcourse);    for (vector<int>::iterator YB = studentGmap[name].begin(); YB != studentGmap[name].end(); YB++)      cout <<" "<< (*YB);    cout << endl;  }  system("pause");  return 0;}

0 0
原创粉丝点击