http://codeforces.com/problemset/problem/237/A
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.
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.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
4 8 0 8 10 8 10 8 45
2
3 0 12 10 11 22 22
1
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash.
这是一道水题,就是要求重复最多的数的个数。。。
说点题外话a ,一个是我的写法,另一个是zx的写法,谁然都A了,我觉得在很多事上是值得我去思考的。。。第一次这么清晰的感觉到读懂题,才用正确的方法,是多么明智的选择。真的,有时候方向比努力更重要。。。
我的:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
int x,y;
};
node a[100005];
int v[100005];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
scanf("%d%d",&a[i].x,&a[i].y);
int sum,maxx=-10000;
memset(v,0,sizeof(v));
for(int i=0; i<n; i++)
{
sum=0;
if(!v[i])
{
v[i]=1;
for(int j=0; j<n; j++)
{
if(a[i].x==a[j].x&&a[i].y==a[j].y)
{sum++;
v[j]=1;
}
}
}
maxx=max(maxx,sum);
}
cout << maxx << endl;
}
return 0;
}
zx的:
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
map<int,int> cash;
int a[500000][2];
int main()
{
int n,count;
while(~scanf("%d",&n))
{
int count=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i][0],&a[i][1]);
int t=a[i][0]*60+a[i][1];
cash[t]++;
if(count<cash[t])
count=cash[t];
}
printf("%d\n",count);
}
return 0;
}