刚看到以为要按照1039反过来做呢,
ref:
关键是没有用string, 而是搞了个char[5]数组,然后包装进一个struct;
我猜是对string做copy和比较都会比较慢吧,算了,懒得用string去做实验了。
主要是构造了数组链表:
vectorcourses[2500+5];//数组链表
#include#include #include #include using namespace std;typedef struct{ char name[5];}student;//不直接用string而用structint n, k;vector courses[2500+5];//数组链表bool cmp(const student a, const student b){// 注意参数是const student,fuck! return (strcmp(a.name,b.name)<=0);}int main(){ freopen("in.txt","r",stdin); scanf("%d%d",&n,&k); char tmpName[5]; int c; for(int i = 0; i < n; i++){ scanf("%s%d",&tmpName,&c); student tmpStu; strcpy(tmpStu.name, tmpName); for(int j = 0; j < c; j++){ int cno; scanf("%d",&cno); courses[cno].push_back(tmpStu);//不需要对courses作初始化操作,amazing } } for(int i = 1; i <=k; i++){ printf("%d %d\n",i,courses[i].size()); sort(courses[i].begin(), courses[i].end(), cmp); for(vector ::iterator it = courses[i].begin();it!=courses[i].end();it++){ printf("%s\n",it->name); } } return 0;}