B-开门人和关门人(优先队列)

来源:互联网 发布:人皇sky有多厉害 知乎 编辑:程序博客网 时间:2024/04/29 08:54

开门人和关门人

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8519    Accepted Submission(s): 4412


Problem Description
每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签 
到、签离记录,请根据记录找出当天开门和关门的人。 
 

Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。 
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为 

证件号码 签到时间 签离时间 

其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
 

Output
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。 
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前, 
且没有多人同时签到或者签离的情况。 
 

Sample Input
31ME3021112225321 00:00:00 23:59:592EE301218 08:05:35 20:56:35MA301134 12:35:45 21:40:423CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40
 

Sample Output
ME3021112225321 ME3021112225321EE301218 MA301134SC3021234 CS301133
 

Source
浙大计算机研究生复试上机考试-2005年
 

Recommend
JGShining


很简单的一道题目哇,用优先队列就是不错呀,省去排序的时间了,就是重载一下大于号,小于号的事,其实和排序的时间是差不多的,

这个是个水题.


#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <queue>using namespace std;int N;int M;struct Node{char card[33];char arrived[22];char left[22];/*void setData(){int len = strlen(arrived);char temp1[22];char temp2[22];int cnt = 0;for (int i = 0; i < len; i++){if (i == 0){temp1[cnt] = arrived[i];temp2[cnt++] = left[i];continue;}if (i % 2 == 0){continue;}temp1[cnt] = arrived[i];temp2[cnt++] = left[i];}strcpy(arrived, temp1);strcpy(left, temp2);cout << arrived << endl;cout << left << endl;}*/friend bool operator < (const Node& a, const Node& b){if (strcmp(a.arrived, b.arrived) == 1){return true;}else{return false;}}friend bool operator > (const Node& a, const Node& b){if (strcmp(a.left, b.left) == -1){return true;}else{return false;}}};priority_queue < Node, vector <Node>, less<Node> > Q1;priority_queue < Node, vector <Node>, greater<Node> > Q2;void init(){while (!Q1.empty()){Q1.pop();}while (!Q2.empty()){Q2.pop();}}int main(){Node node;while (scanf("%d", &N) != EOF){while (N--){init();scanf("%d", &M);for (int i = 0; i < M; i++){scanf("%s%s%s", node.card, node.arrived, node.left);Q1.push(node);Q2.push(node);}Node ans1 = Q1.top();Node ans2 = Q2.top();printf("%s %s\n", ans1.card, ans2.card);}}//system("pause");return 0;}



原创粉丝点击