Let's go to play
Time limit:3000/1000ms (java/other) Memory limit:65535/32768k (java/other)
Total Submission (s): 773 Accepted Submission (s): 213
font:times New Roman | Verdana | Georgia
Font size:←→
problem DescriptionMr.lin would a party and invite he friends to the party. He has n friends and each of them can come in a specific range of days of the year from AI to bi.
Mr.lin wants to arrange a day, he can invite more friends. But he has a strange request, the number of male friends should equal to the number of femal friends.
InputMultiple sets of test data.
The first line of all input contains a single integer n (1<=n<=5000)
then follow n lines. Each line starts with a capital letter ' F ' for female and with a capital letter ' M ' for male. Then follow-integers AI and bi (1<=ai,bi<=366), providing that the i-th friend can come to the party from day AI To day bi inclusive.
OutputPrint The maximum number of people.
Sample Input
4
M 151 307
F 343 352
F 117 145
M 6 m (mm)
F 131
F 131 +
F 131 141
m 131
M 140 200
Sample Output
2
4
Ac-code:
#include <stdio.h>
#include <cstring>
using namespace std;
int main ()
{
int n,i,j,f[370],m[370],st,ed,max;
char c;
while (~SCANF ("%d", &n))
{
memset (f,0,sizeof (f));
memset (M,0,sizeof (m));
for (i=0;i<n;i++)
{
getchar ();
scanf ("%c", &c);
scanf ("%d%d", &st,&ed);
if (st>ed)
j=st,st=ed,ed=j;
if (c== ' F ') for
(j=st;j<=ed;j++)
f[j]++;
else for
(j=st;j<=ed;j++)
m[j]++;
}
max=0;
for (i=1;i<=366;i++)
if (F[i]>max&&m[i]>max)
max=f[i]>m[i]?m[i]:f[i];
printf ("%d\n", 2*max);
}
return 0;
}