Let's go to play
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 770 Accepted Submission(s) : 213
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Mr.Lin would like to hold a party and invite his friends to this 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 that the number of male friends should equal to the number of femal friends.
Mr.Lin wants to arrange a day, he can invite more friends. But he has a strange request that the number of male friends should equal to the number of femal friends.
Input
Multiple sets of test data.
The first line of each 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 two 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.
The first line of each 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 two 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.
Output
Print the maximum number of people.
Sample Input
4 M 151 307 F 343 352 F 117 145 M 24 128 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200
Sample Output
2 4
Author
bytelin
解体思路:一上来就用排序写,Wa的头都要混了,结束后队友和我说数组非常小,最大只有400,遍历数组既不会超时,也不会WA。分别记录男生和女生每天的到来情况,再筛选出男女出席对数最多的那一天就OK了。
代码如下:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int map1[400],map2[400];
int main(){
int n,i,j,x,y,ans;
char s[2];
while(scanf("%d",&n)!=EOF){
memset(map1,0,sizeof(map1));
memset(map2,0,sizeof(map2));
for(i=0;i<n;i++){
memset(s,0,sizeof(s));
scanf("%s%d%d",s,&x,&y);
if(s[0]=='M'){
for(j=x;j<=y;j++){
map2[j]++;
}//记录每天可以来的男生数
}
else{
for(j=x;j<=y;j++)
map1[j]++;//记录每天可以来的女生数
}
}
ans=0;
for(i=1;i<=366;i++){
ans=max(ans,min(map1[i],map2[i])*2);//算出某天可以达到的最多人数
}
printf("%d\n",ans);
}
return 0;
}