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;
    }
  • 相关阅读:
    抽象理解切片递归神经网络(SRNN)的结构
    通俗点讲解 RNN、LSTM、GRU
    2019年最强的自然语言处理模式BERT
    LSTM训练机器理解人类交流的进展
    人工智能自动写作软件基于通用预训练方法MASS
    如何理解模拟计算机“大脑”所形成的神经网络
    人工智能自动写作软件2.0时代
    解开神秘的面纱,人工智能算法到底是什么
    人工智能算法有哪些?启发式算法原理
    浅谈人工智能神经网络与工业自动化
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5205717.html
Copyright © 2011-2022 走看看