基本思想:
无;
关键点:
主要是性能优化的问题:
1.能尽量使用scanf和printf尽量使用,cin&&cout性能过低,会tl;
2.大型样本空间下,使用char[]要比string高效;
3.极其重要:一种新的思想,针对于字符串排序可以直接排序索引,可以省去大量的复制和移动操作;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> #include<map> #include<queue> using namespace std; const int maxn = 40010; int n, k; vector<int> per[maxn]; char stu[maxn][5]; bool cmp(int a, int b) { return strcmp(stu[a],stu[b])<0; } int main() { scanf("%d %d", &n, &k); string s; int a,b; for (int i = 0; i < n; i++) { scanf("%s %d", stu[i], &a); for (int j = 0; j < a; j++) { scanf("%d",&b); per[b].push_back(i); } } for (int i = 1; i <= k; i++) { printf("%d %d\n", i, per[i].size()); sort(per[i].begin(), per[i].end(), cmp); for (int j = 0; j < per[i].size(); j++) { printf("%s\n", stu[per[i][j]]); } } return 0; }
1047 Student List for Course (25point(s)) 需要二刷 *需要重点注意关于性能得问题
原文:https://www.cnblogs.com/songlinxuan/p/12340531.html