zoukankan      html  css  js  c++  java
  • 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 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

    4
    M 151 307
    F 343 352
    F 117 145
    M 24 128

    Sample Output

    2

    Hint

    题意

    有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;
    }
  • 相关阅读:
    MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
    如何安装mongodb.msi
    jade和ejs两者的特点
    Node.js中的http.request方法的使用说明
    34丨关于Linux网络,你必须知道这些(下)
    33 | 关于 Linux 网络,你必须知道这些(上)
    osi 七层模型 通俗易懂
    32 | 浅谈容器网络
    Linux 三剑客之SED行天下
    js 基本类型与引用类型的区别
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5205717.html
Copyright © 2011-2022 走看看