codeforces 629BFar Relative’s Problem
2 seconds
256 megabytes
standard input
standard output
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 biinclusive.
Print the maximum number of people that may come to Famil Door's party.
4
M 151 307
F 343 352
F 117 145
M 24 128
2
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 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<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 5100
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
int n,j,i,t;
char op[3];
while(scanf("%d",&n)!=EOF)
{
int m[MAX],f[MAX];
int beg,end;
memset(m,0,sizeof(m));
memset(f,0,sizeof(f));
for(i=1;i<=n;i++)
{
scanf("%s%d%d",op,&beg,&end);
if(op[0]=='M')
for(j=beg;j<=end;j++)
m[j]++;
else
for(j=beg;j<=end;j++)
f[j]++;
}
int sum=-INF;
int F,M;
F=M=0;
for(i=1;i<=366;i++)
sum=max(sum,min(m[i],f[i]));
printf("%d\n",sum*2);
}
return 0;
}
codeforces 629BFar Relative’s Problem的更多相关文章
- 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 ...
- 【26.09%】【codeforces 579C】A Problem about Polyline
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- Codeforces 442B Andrey and Problem(贪婪)
题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...
- CodeForces 867B Save the problem
B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...
- Codeforces 776D The Door Problem
题目链接:http://codeforces.com/contest/776/problem/D 把每一个钥匙拆成两个点${x,x+m}$,分别表示选不选这把钥匙. 我们知道一扇门一定对应了两把钥匙. ...
- codeforces 803G Periodic RMQ Problem
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...
随机推荐
- treap完全版模板
这是我综合poj1442 3481 2352的treap操作 得到treap完全版模板.(经测AC) 结构体Tree { int key; //键值 int size; //该子树总节点个数 int ...
- LA 2402 (枚举) Fishnet
题意: 正方形四个边界上分别有n个点,将其划分为(n+1)2个四边形,求四边形面积的最大值. 分析: 因为n的规模很小,所以可以二重循环枚举求最大值. 求直线(a, 0) (b, 0) 和直线(0, ...
- MongoDB入门分享-笔记整理精选
最近在学习MongoDB,怕以后忘记,自己做了一个整理,给不知道的小伙伴一起分享学习一下. 第一步> 首先到官网下载,安装MongoDB.(注意MongoDB还有一个可视化管理工具叫: Mong ...
- asp.net输出docx文档出现【文件已损坏 无法打开】问题的解决方案
在某个项目中,有个需求需要将一些附件文档以字节流的形式直接存储在数据库中. 功能实现后,尝试过很多格式文件的上传下载处理,均未发现问题, 唯独在下载docx格式文件后,一打开文件就提示: “无法打开文 ...
- ORACLE 全局索引和本地索引
Oracle数据库中,有两种类型的分区索引,全局索引和本地索引,其中本地索引又可以分为本地前缀索引和本地非前缀索引.下面就分别看看每种类型的索引各自的特点. 全局索引以整个表的数据为对象建立索引,索引 ...
- TCP/IP详解学习笔记(7)-广播和多播,IGMP协议
1.单播,多播,广播的介绍 1.1.单播(unicast) 单播是说,对特定的主机进行数据传送.例如给某一个主机发送IP数据包.这时候,数据链路层给出的数据头里面是非常具体的目的地址,对于以太网来 说 ...
- Ruby 文件处理
#r read, #w write, #a append, #r+ 读写方式 从文件的头位置开始读取或写入, #w+ 读写方式,如果文件已存在清空该文件,不存在就创建一个新的文件, #a+ 如果文件存 ...
- 利用反射自动生成SQL语句(仿Linq)
转:http://www.cnblogs.com/the7stroke/archive/2012/04/22/2465597.html using System; using System.Colle ...
- Java SE 6 新特性: Java DB 和 JDBC 4.0
http://www.ibm.com/developerworks/cn/java/j-lo-jse65/index.html 长久以来,由于大量(甚至几乎所有)的 Java 应用都依赖于数据库,如何 ...
- Android应用程序版本号管理(官方文档中文版)
在应用程序的 升级/维护 策略中, 版本是一个关键的组成部分. 用户需要了解在他们的设备上所安装的应用程序的版本的特定信息, 以及已安装程序的升级版本可用的情况. 其他应用程序 - 作为同一个套件中发 ...