Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
2016-02-21 22:15
519 查看
B. Far Relative’s Problem
题目连接:
http://www.codeforces.com/contest/629/problem/BDescription
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
4M 151 307
F 343 352
F 117 145
M 24 128
Sample Output
2Hint
题意
有n个人M/F 表示这个人的性别,Li,Ri,表示这个人[Li,Ri]都可以来
你需要找到一天,男女成对的数量最多,问你这天成对的数量*2是多少
题解:
直接暴力,然后扫一遍就好了代码
#include<bits/stdc++.h> using namespace std; const int maxn = 400; int a[2][maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { char s[3];int l,r; scanf("%s%d%d",s,&l,&r); if(s[0]=='M') { for(int j=l;j<=r;j++) a[0][j]++; } else { for(int j=l;j<=r;j++) a[1][j]++; } } int ans = 0; for(int i=0;i<=366;i++) ans=max(ans,2*min(a[0][i],a[1][i])); cout<<ans<<endl; }
相关文章推荐
- 内存分配学习(一)-- 实现一个malloc
- Sublime Text3 3103 注册码
- android基础之一——android下的数据库
- 二叉树的遍历(C++)版
- cvWaitKey
- js实现的随机颜色实例代码
- 安卓第二天笔记-数据保存
- IntelliJ IDEA 14 创建maven项目二
- Spinner
- [Lintcode]Merge Sorted Array
- [Matlab]使用Simulink进行UDP通讯1
- C#public/protected/private/internal/protected internal
- 用Qt实现一个桌面弹幕程序(五)-- -- 桌面客户端实现①
- 《世界是数字的》(1/4)
- Question and Answer
- CSS 选择器 element.id 与element .id element.class 与 element .class
- android基础之二——网络编程(二)
- 详解Android中AsyncTask的使用
- 查看索引
- 异常处理