Far Relative’s Problem【 区间覆盖】
2017-03-17 08:07
309 查看
S-FarRelative’sProblem
FamilDoorwantstocelebratehisbirthdaywithhisfriendsfromFarFarAway.Hehas
nfriendsandeachofthemcancometothepartyinaspecificrangeofdaysoftheyearfrom
aito
bi.Ofcourse,FamilDoorwantstohaveasmanyfriendscelebratingtogetherwithhimaspossible.
FarcarsareasweirdasFarFarAwaycitizens,sotheycanonlycarrytwopeopleofoppositegender,thatisexactlyonemaleandonefemale.However,Farissofarfromherethatnoothertransportationmaybeusedtogettotheparty.
FamilDoorshouldselectsomedayoftheyearandinvitesomeofhisfriends,suchthattheyallareavailableatthismomentandthenumberofmalefriendsinvitedisequaltothenumberoffemalefriendsinvited.Findthemaximumnumberoffriendsthat
maypresentattheparty.
Input
Thefirstlineoftheinputcontainsasingleintegern(1 ≤ n ≤ 5000) —thennumberofFamilDoor'sfriends.
Thenfollownlines,thatdescribethefriends.Eachlinestartswithacapitalletter'F'forfemalefriendsandwithacapitalletter'M'
formalefriends.Thenfollowtwointegersaiand
bi(1 ≤ ai ≤ bi ≤ 366),providingthatthe
i-thfriendcancometothepartyfromday
aitoday
biinclusive.
Output
PrintthemaximumnumberofpeoplethatmaycometoFamilDoor'sparty.
Example
Input
4 M151307 F343352 F117145 M24128
Output
2
Input
6 M128130 F128131 F131140 F131141 M131200 M140200
Output
4
Note
Inthefirstsample,friends3and
4cancomeonanydayinrange[117, 128].
Inthesecondsample,friendswithindices3,
4,5and6cancomeonday
140.
思路区间覆盖的变形,对于每个元素用两个变量记录就可以
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<vector>
#defineinf0x3f3f3f
#definemod100000
#defineM400
usingnamespacestd;
structdata
{
intxx,yy;
};
dataa[M];
intmain()
{
intn;
while(~scanf("%d",&n))
{
for(inti=0;i<M;i++)
a[i].xx=a[i].yy=0;
for(inti=0;i<n;i++)
{
chark;
intx,y;intkk;
getchar();
scanf("%c%d%d",&k,&x,&y);
if(k=='M')kk=1;
elsekk=0;
for(intj=x;j<=y;j++)
{
if(kk)a[j].yy++;
elsea[j].xx++;
}
}
intsum=0;
for(inti=0;i<M;i++)
{
if(a[i].xx&&a[i].yy)
{
intll=min(a[i].xx,a[i].yy);
if(ll*2>sum)sum=ll*2;
}
}
printf("%d\n",sum);
}
return0;
}
相关文章推荐
- H - Far Relative’s Problem 【区间覆盖】
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem (线段树+区间更新+单点查询)
- 【Codeforces】-629B-.Far Relative’s Problem(贪心.时间区间)
- Codeforces Far Relative’s Problem(区间贪心)
- Codeforces--629B--Far Relative’s Problem(模拟)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem (贪心)
- Codeforces--629B--Far Relative’s Problem(模拟)
- Far Relative’s Problem(贪心算法)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem(O(1)的线段标记)
- CodeForces Far Relative’s Problem (贪心)
- Far Relative’s Problem
- Codeforces Round #343 (Div. 2) -B. Far Relative’s Problem(模拟)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
- Far Relative’s Problem(贪心模拟)
- Far Relative’s Problem
- codeforces 629-B. Far Relative’s Problem(思想)
- 【Codeforces 贪心】Far Relative’s Problem
- 【codeforces】 Far Relative’s Problem
- Far Relative’s Problem(贪心)