codefoces-Far Relative’s Problem

题目
B. Far Relative’s Problem
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.

Examples
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
Note
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.

(简单思路题)
**题意:
**给你一组数据,数据中M表示男生,F表示女生,每个字母后面跟两个数字,第一个数字是表示这个人可以从这一天(包含这一天)去参加聚会,第二个数字表示到这一天(也包含这一天)结束。
首先知道,去参加的聚会的人必须是一对,问你找到一个时间(某一天)找出能参加的聚会的最多的对,并输出参加人数;

解决:暴力;

我们可以把每个F和M的每个时间段分别都标记出现次数,然后找出它们同一时间段里标记出现小的那个就是可以组成对的个数,然后乘与2就是人数,依次找即可;

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
const int num=50005;
int b[num];
int c[num];
int main()
{
    int t,x,y;
    cin>>t;
    getchar();
    char a;
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(int i=1;i<=t;i++)
    {
        cin>>a>>x>>y;
        if(a=='M')
        for(int j=x;j<=y;j++)
        {
            b[j]++;
        }
        else if(a=='F')
        {
            for(int j=x;j<=y;j++)
            {
                c[j]++;
            }
        }
    }
    int sum=0;
    for(int i=1;i<=5000;i++)
    {
        if(sum<(min(b[i],c[i])*2))
        sum=(min(b[i],c[i])*2);
    }
    cout<<sum;
    return 0;
}
全部评论

相关推荐

05-12 10:10
已编辑
门头沟学院 人工智能
写这篇之前我犹豫了挺久。一方面是怕被人骂,&quot;又一个收割焦虑的转行帖&quot;;另一方面是看了太多用&nbsp;GPT&nbsp;套娃出来的「学习路线」文章,AI&nbsp;味重得让人没法读完。所以这篇全是亲身踩过的坑,时间线、用过的项目、当时的心路全都尽量原样写出来。如果你是大学生在迷茫要不要转&nbsp;AI,或者已经在转的路上,希望能给点参考。&nbsp;一个反共识的开场:你以为进&nbsp;OpenAI&nbsp;的人都是博士?&nbsp;先讲个故事,跟我没关系,但跟所有想转&nbsp;AI&nbsp;的人都有关系。&nbsp;OpenAI&nbsp;的&nbsp;Sora&nbsp;团队(就是搞文生视频那个)一共&nbsp;13&nbsp;个人。这里面有两个人特别有意思:&nbsp;Will&nbsp;DePue,密歇根大学计算机系,直接辍学了。17...
_hengheng:我也本,也算是做ai相关,我最开始感觉做ai工程师有多么多么困难,后来发现懂了原理后整体训练完全可以看成一个流程化的内容,开源方案太多了,大多基本都是按着模子在自家业务上做各种操作,就算是大厂的小部门也没那么多资源去训基模,反而更多的是像怎么把技术往业务方向靠近了,不过当前时代如果本科学历没那么好加上自己执行力不是特别强还真不建议走ai工程师这条路,可以试试其他ai的偏业务方向,不然校招不太好杀出来
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务