1039. Course List for Student (25)

来源:互联网 发布:python ide vs 编辑:程序博客网 时间:2024/06/06 22:52

1.存在超时的危险

2.根据题意,名字由3个字母和1个数字组成,所以共26*26*26*10=175760种可能,直接开辟内存


AC截图:

//#include<string>//#include <iomanip>#include<vector>#include <algorithm>//#include<stack>#include<set>#include<queue>#include<map>//#include<unordered_set>#include<unordered_map>//#include <sstream>//#include "func.h"//#include <list>#include<stdio.h>#include<iostream>#include<string>#include<memory.h>#include<limits.h>using namespace std;/*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*/int main(void){int querySum, courseSum;cin >> querySum >> courseSum;vector<set<int>>stu(175761);//3个字母+1个数字,共26*26*26*10=175760种可能,直接开辟内存for (int i = 0; i<courseSum; i++){int courseIdx, studentSum;scanf("%d %d", &courseIdx, &studentSum);for (int j = 0; j<studentSum; j++){char tmp[5];scanf("%s", tmp);int name = (tmp[0]-'A')*26*26*10;name += (tmp[1] - 'A') * 26*10 + (tmp[2] - 'A') * 10 + tmp[3]-'0';stu[name].insert(courseIdx);}}for (int i = 0; i<querySum; i++){char tmp[5];scanf("%s", tmp);int name = (tmp[0] - 'A') * 26 * 26 * 10;name += (tmp[1] - 'A') * 26 * 10 + (tmp[2] - 'A') * 10 + tmp[3] - '0';printf("%s %d",tmp,stu[name].size());for (set<int>::iterator ite = stu[name].begin(); ite != stu[name].end(); ite++){printf(" %d", *ite);}cout << endl;}return 0;}


0 0
原创粉丝点击