1039.Course List for Student (25)...to be continued...
2017-02-24 22:06
429 查看
1039.Course List for Student (25)…to be continued…
pat-al-1036
2017-02-24
一道大坑的题,看了题觉得用map和set来写,然而!竟然会超时,因为数据量太大了
启发:遇到比较大的数据量,避免cout和cin,以及考虑用vector来写而非数组,也尽量不要用map来写
-TBC-
pat-al-1036
2017-02-24
一道大坑的题,看了题觉得用map和set来写,然而!竟然会超时,因为数据量太大了
启发:遇到比较大的数据量,避免cout和cin,以及考虑用vector来写而非数组,也尽量不要用map来写
/** * pat-al-1036 * 2017-02-24 * Cpp version * Author: fengLian_s */ #include<stdio.h> #include<algorithm> #include<string> #include<vector> #define MAX (26*26*26*10+1) using namespace std; vector<int> course[MAX]; int convert2ID(char name[]) { int id = 0; for(int i = 0;i < 3;i++) { id = id*26 + name[i] - 'A'; } id = id*10 + name[3] - '0'; return id; } int main() { freopen("in.txt", "r", stdin); int n, k; int index, ni; char name[5]; int id; scanf("%d%d", &n, &k); for(int i = 0;i < k;i++) { scanf("%d%d", &index, &ni); for(int j = 0;j < ni;j++) { scanf("%s", name); id = convert2ID(name); course[id].push_back(index); } } for(int i = 0;i < n;i++) { scanf("%s", name); id = convert2ID(name); sort(course[id].begin(), course[id].end()); printf("%s %lu", name, course[id].size()); for(int j = 0;j < course[id].size();j++) { printf(" %d", course[id][j]); } putchar('\n'); } return 0; }
-TBC-
相关文章推荐
- 1017.Queueing at Bank (25)...to be continued...
- 1044.Shopping in Mars (25)...to be continued...
- 1060.Are They Equal (25)...to be continued...
- 1012.The Best Rank (25)...to be continued...
- 1071.Speech Patterns (25)...to be continued...
- 1047.Student List for Course (25)...to be continued...
- 1082.Read Number in Chinese (25)...to be continued...
- 1020.Tree Traversals (25)...to be continued...
- 1059.Prime Factors (25)...to be continued...
- 1067.Sort with Swap(0,*) (25)...to be continued...
- 1043.Is It a Binary Search Tree (25)...to be continued...
- 1024.Palindromic Number (25)...to be continued...
- 1016.Phone Bills (25)...to be continued...
- 1089.Insert or Merge (25)...to be continued...
- 1056.Mice and Rice (25)...to be continued...
- 1066.Root of AVL Tree (25)...to be continued...
- 1093.Count PAT's (25)...to be continued...
- 1010.Radix (25)...to be continued...
- 1086.Tree Traversals Again (25)...to be continued...
- 1075.PAT Judge (25)...to be continued...