Far Relative’s Problem (贪心 计算来的最多客人)
Description
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.
Input
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.
Output
Print the maximum number of people that may come to Famil Door's party.
Sample Input
Input
4
M 151 307
F 343 352
F 117 145
M 24 128
Output
2
Input
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
Output
4
Hint
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>
int wom[],man[],n,max= ,x,y;
char c;
int main()
{
scanf("%d",&n);
for(int i = ;i<n;i++)
{
scanf("%s %d %d",&c,&x,&y);
if(c == 'M')
{
for(int i = x;i<=y;i++)
{
man[i]++;
}
}
else
{
for(int i = x;i<=y;i++)
{
wom[i]++;
}
}
}
for(int i = ;i<=;i++)
{
if(max < (wom[i]<man[i]?wom[i]:man[i])*)
{
max = *(wom[i]<man[i]?wom[i]:man[i]);
}
}
printf("%d\n",max);
}
Far Relative’s Problem (贪心 计算来的最多客人)的更多相关文章
- codeforces 629BFar Relative’s Problem
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...
- Codeforces 629 B. Far Relative’s Problem
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces--629B--Far Relative’s Problem(模拟)
Far Relative's Problem Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I ...
- 计算"aabbc"中最多的相同字母数
package Test; import java.util.HashMap; import java.util.Map; public class test3 { /** * 计算"aab ...
- an easy problem(贪心)
An Easy Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8333 Accepted: 4986 D ...
- CF #296 (Div. 1) B. Clique Problem 贪心(构造)
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- mui 每次页面跳转用mui.openWindow会不会占用很大内存?
http://ask.dcloud.net.cn/question/5384 不能每次用mui.openWindow.不用的webview要close,一个webview被close后会露出其他没有被 ...
- Dexposed:android免Root无侵入Aop框架
在网上看到了阿里推出的一个android开源项目,名为Dexposed, 是一个Android平台下的无侵入运行期AOP框架.旨在解决像性能监控.在线热补丁等移动开发常见难题,典型使用场景为: AOP ...
- InputFilter在过滤空格时重复输入的问题
正确做法:editText.setFilters(new InputFilter[] { new InputFilter() { @Override public CharSequence filte ...
- 如何移除EditText自动焦点
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_cont ...
- iOS判断输入的字符串是否是纯数字
主要用于判断输入到TextField的内容是不是数字,比如需要输入电话号码的时候. 网上查看了一些资料,一般都是通过协议. 以下内容来自:http://www.2cto.com/kf/201404/2 ...
- 关于springMVC传参问题
今天写项目,碰到一个以前灭有注意到的问题,一般情况下使用springMVC @Controller注解之后,被此注解标记的方法的参数名只需要跟页面表单的标签的name的值相同即可拿到页面的值,但是如果 ...
- Javascript IE 内存释放
一个内存释放的实例 <SCRIPT LANGUAGE="JavaScript"><!--strTest = "1";for ( var i = ...
- struts2的action是线程安全的,struts1的action不是线程安全的真正原因
为什么struts2的action是线程安全的,struts1的action不是线程安全的? 先对struts1和struts2的原理做一个简单的讲解 对于struts1 ,当第一次**.do的请求过 ...
- github——团队合作
- 【PostgreSQL-9.6.3】启动,登录,退出,关闭
当我们费尽千辛万苦安装完数据库后,一定会迫不及待的想使用它.骚年,不要着急,且看我为您解析PostgreSQL的启动,登录,退出,关闭过程. 一 启动数据库服务器 1. 没有设置环境变量的情况下 po ...