练习codeforces237A. Free Cash
题目如下
A. Free Cash
time limit per test2 seconds
memory limit per test256 megabytes
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), that is the number of cafe visitors.
Each of the following n lines has two space-separated integers hi and mi (0 ≤ hi ≤ 23; 0 ≤ mi ≤ 59), representing the time when the i-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
题目大意
在一天内的各个时间点可能都有客人来消费,在某个时间点可能有最多的人,每个客人都要接待到,那么最多需要多少个柜台
题目分析
这同样是一个求”众数“的题目,现在求的是需要的最大柜台数,只要统计出人最多的时刻的人数即可
那么我本想定义一个关于时间的结构体,但是在统计时又带来麻烦,所以我们用pair<>,同样是一个小的结构体,这样我们就可以使用map更加便捷地进行统计频率了
点击查看代码
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
int main(){
int n, max = 0;
scanf("%d", &n);
map<pair<int, int>, int> freq;
int h, m;
for(int i = 0; i < n; i++){
scanf("%d %d",&h, &m);
freq[{h,m}]++;
if(freq[{h,m}] > max){
max = freq[{h,m}];
}
}
printf("%d ",max);
return 0;
}

浙公网安备 33010602011771号