H - Far Relative’s Problem 【区间覆盖】
来源:互联网 发布:新点计价软件 编辑:程序博客网 时间:2024/06/08 11:16
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.
Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.
Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. 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.
Print the maximum number of people that may come to Famil Door's party.
4M 151 307F 343 352F 117 145M 24 128
2
6M 128 130F 128 131F 131 140F 131 141M 131 200M 140 200
4
In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int min(int x,int y){if(x>y)return y;return x;}int main(){int n,ts,te,a[5010],b[5010],c[5010],minn,maxn;char sex[10];while(~scanf("%d",&n)){minn=5010;maxn=0;memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));for(int i=0;i<n;i++){scanf("%s",sex);getchar();scanf("%d%d",&ts,&te);if(maxn<te)maxn=te;if(minn>ts)minn=ts;if(strcmp(sex,"F")==0){for(int i=ts;i<=te;i++){a[i]++;}}else {for(int i=ts;i<=te;i++){b[i]++;}}}for(int i=minn;i<=maxn;i++){if(a[i]&&b[i])c[i]=min(a[i],b[i]);}sort(c+minn,c+maxn+1);printf("%d\n",c[maxn]*2);}return 0;}
- H - Far Relative’s Problem 【区间覆盖】
- Far Relative’s Problem【 区间覆盖】
- Far Relative’s Problem
- Far Relative’s Problem
- Far Relative’s Problem
- Codeforces 629B Far Relative’s Problem(简单区间贪心)
- Codeforces 629B Far Relative’s Problem(简单区间贪心)
- Codeforces Far Relative’s Problem(区间贪心)
- Codeforces 629B Far Relative’s Problem 区间贪心
- B. Far Relative’s Problem
- 【codeforces】Far Relative’s Problem
- 【codeforces】 Far Relative’s Problem
- CodeForces 629B Far Relative’s Problem
- B. Far Relative’s Problem【思维】
- Far Relative’s Problem(贪心算法)
- CodeForces Far Relative’s Problem (贪心)
- Far Relative’s Problem(贪心模拟)
- codrecorces B. Far Relative’s Problem
- 字符串查找最长子串
- 随想-如何成为出色的程序员
- PAT-1002
- 通向架构师的道路(第一天)之Apache整合Tomcat
- 九大排序算法再总结
- H - Far Relative’s Problem 【区间覆盖】
- Doing Homework again
- netstat常用命令
- 2016.07.12【初中部 NOIP提高组 】模拟赛C
- openstack的搭建
- [LeetCode刷题笔记]Math数学类型题目(一)重写基本运算符
- 使用Github的Webhooks进行网站的自动化部署
- 实验项目3-6:表达式转换(中缀表达式转后缀表达式)
- 51NOD 1060 最复杂的数