日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1039 Course List for Student (25 分)_33行代码AC

發(fā)布時間:2024/2/28 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1039 Course List for Student (25 分)_33行代码AC 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

立志用最少的代碼做最高效的表達


PAT甲級最優(yōu)題解——>傳送門


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 (≤40,000), the number of students who look for their course lists, and K (≤2,500), 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 N?i(≤200) are given in a line. Then in the next line, N?i 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 5
4 7
BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
1 4
ANN0 BOB5 JAY9 LOR6
2 7
ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
3 1
BOB5
5 9
AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9

Sample Output:
ZOE1 2 4 5
ANN0 3 1 2 5
BOB5 5 1 2 3 4 5
JOE4 1 2
JAY9 4 1 2 4 5
FRA8 3 2 4 5
DON2 2 4 5
AMY7 1 5
KAT3 3 2 4 5
LOR6 4 1 2 4 5
NON9 0


題意:N個查詢對象, K個學院(從1開始命名),接下來有K組數(shù)據(jù):學院編號、學院內的學生、每個學生的名字。

最后輸入N個查詢對象的名字,查詢他們在哪些學院, 輸出名字、所在學院個數(shù)、每個學院編號(升序輸出)


分析:建立map映射,由于用名字查詢,因此名字為key, 所在學院為value。 又因為學院數(shù)可能有多個,因此value為數(shù)組形式(vector)。

改進:string類型的數(shù)組做key查詢起來十分耗時,可以將其散列化為int型數(shù)據(jù)存儲。


代碼

#include<bits/stdc++.h> using namespace std; vector<vector<int>>hashTable((int)1e6); int strhash(const string&s) {int k = 0;for(int i = 0; i < 3; i++) {k = k*26+s[i]-'A';}k = k*26+s[3]-'0';return k; } int main() {ios::sync_with_stdio(false);int N, K; cin >> N >> K;string name; for(int i = 1; i <= K; i++) {int cour, num; cin >> cour >> num;while(num--) {cin >> name;hashTable[strhash(name)].push_back(cour);}}while(N--) {cin >> name; //不要在循環(huán)里定義string,很耗時。 int k = strhash(name);cout << name << ' ' << hashTable[k].size();sort(hashTable[k].begin(), hashTable[k].end());for(int i = 0; i < hashTable[k].size(); i++) cout << ' ' << hashTable[k][i];cout << '\n';}return 0; }

耗時:


求贊呀~

總結

以上是生活随笔為你收集整理的1039 Course List for Student (25 分)_33行代码AC的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 五色天婷婷 | 久久综合桃花网 | 亚洲精品久久久久久宅男 | 国产av成人一区二区三区高清 | 日韩色黄大片 | 久草免费在线观看视频 | 四级毛片| 欧美在线中文字幕 | 国产黄色大片视频 | 国产精品无码中文 | 国产免费看片 | 中文字幕在线2021 | 国产字幕av| 日本激情一区 | 亚洲精品成人片在线观看精品字幕 | 亚洲精品国产无码 | 91视频黄| 综合狠狠开心 | 国产又粗又大又硬 | 欧美日韩一区二区中文字幕 | 国产精品亚洲成在人线 | 欧美色999 | 99成人在线观看 | 精品av一区二区 | 性生交大片免费看l | 91毛片网站 | 亚洲精品伊人 | 久久2018| 爱如潮水3免费观看日本高清 | 国产成人一区二区三区小说 | a√在线观看 | 国产999在线观看 | 伊人网址 | 特级大胆西西4444人体 | 999在线观看视频 | 韩日成人 | 精品久久久久久中文字幕人妻最新 | 中文字幕第九页 | 精品婷婷| 91久久综合精品国产丝袜蜜芽 | 亚洲在线免费看 | 天堂√ | 欧美日一区二区三区 | 欧洲自拍一区 | 轻点好疼好大好爽视频 | 亚洲高清在线免费观看 | 久久久久久免费视频 | 原来神马电影免费高清完整版动漫 | 蜜桃做爰免费网站 | 少妇全黄性生交片 | 色吟av| 天堂影视av | 亚洲最新偷拍 | 韩日av| 青娱乐超碰 | 韩国av网| jizz日本大全| 国产精品91av | 免费看又黄又无码的网站 | 国产小视频自拍 | 大奶子在线观看 | 国产视频三区 | 国产精品电影一区二区三区 | 黄网站色视频免费观看 | 日韩欧美在线视频 | 国产毛片基地 | 成年人观看视频 | 亚洲欧美日韩国产一区 | 国产偷拍一区二区三区 | 欧美xxxx888 | 欧美自拍一区 | 三级国产网站 | 动漫女被黄漫免费视频 | 国产 欧美 日韩 在线 | 成人亚洲电影 | 五月天激情丁香 | 姝姝窝人体www聚色窝 | 亲切的金子片段 | 91久久人澡人人添人人爽欧美 | 日本一区二区三区四区五区 | 日本在线中文 | 女人叉开腿让男人桶 | 日本打白嫩屁股视频 | 91禁在线看| 久久国产精品波多野结衣av | 日韩欧美高清片 | 国产青青草视频 | 韩国美女一区 | 少妇精品视频 | 日本高清黄色电影 | 久久天堂av | 国产伦精品一区二区三区视频网站 | 美女的隐私免费看 | 色爽爽爽爽爽爽爽爽 | 黄色一级片在线播放 | 国产无限资源 | 国产成人黄色片 | 中文字幕一二 | 99久久婷婷国产精品综合 |