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.
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.
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
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.
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.
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
区间加法。。。。
详情算法可点击问题 K: 序列的区间操作
代码;
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int male[10050];
int fele[10050];
int fe[10050];
int ma[10050];
int ren[10050];
int main()
{
char ch[2];
int n,a,b;
while (~scanf("%d",&n))
{
memset(male,0,sizeof(male));
memset(fele,0,sizeof(fele));
memset(ma,0,sizeof(ma));
memset(fe,0,sizeof(fe));
for (int i=1;i<=n;i++)
{
scanf("%s%d%d",ch,&a,&b);
if (ch[0]=='M')
{
ma[a]++;ma[b+1]--;
}
else
{
fe[a]++;fe[b+1]--;
}
}
for (int i=1;i<=366;i++)
{
fele[i]=fele[i-1]+fe[i];
male[i]=male[i-1]+ma[i];
ren[i]=min(fele[i],male[i]);
}
ren[0]=0;
sort(ren,ren+367);
printf("%d\n",ren[366]*2);
}
return 0;
}