zoukankan      html  css  js  c++  java
  • Codeforces 629 B. Far Relative’s Problem

     
     
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    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 biinclusive.

    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.

    代码:

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <string>
     9 #include <queue>
    10 #include <vector>
    11 using namespace std;
    12 const int maxn= 500;
    13 const double eps= 1e-6;
    14 const int inf = 0x3f3f3f3f;
    15 typedef long long ll;
    16 int n,m,k;
    17 int d1[maxn],d2[maxn];
    18 char a;
    19 int s,e;
    20 int main()
    21 {
    22     scanf("%d",&n);
    23     memset(d1,0,sizeof(d1));
    24     memset(d2,0,sizeof(d2));
    25     for(int i=1;i<=n;i++)
    26     {
    27         cin>>a>>s>>e;
    28         if(a=='M')
    29         {
    30             for(int i=s;i<=e;i++)
    31                 d1[i]++;
    32         }
    33         else if(a=='F')
    34         {
    35             for(int i=s;i<=e;i++)
    36                 d2[i]++;
    37         }
    38     }
    39     int ans=0;
    40     for(int i=1;i<=366;i++)
    41     {
    42         int x=min(d1[i],d2[i]);
    43         ans=max(ans,x);
    44     }
    45     printf("%d
    ",ans*2);
    46     return 0;
    47 }
  • 相关阅读:
    【Linux】Gitlab库已损坏前端显示500错误解决方法
    【linux】gitlab 的安装以及数据迁移
    【PHP】图片转换为base64,经过post传输后‘+’会变成 ‘空格’
    【Mac】解决外接显示器时无法用键盘调节音量
    【Mac】 /usr/local 文件夹权限问题
    学妹问的Spring Bean常用配置,我用最通俗易懂的讲解让她学会了
    上海月薪 1w 和家乡月薪 5000 你选择哪?
    30岁码农的一次面试经历:不委屈自己
    写4条宝贵的经验,给初入职场的你
    Java 8 Optional 良心指南,建议收藏
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9695517.html
Copyright © 2011-2022 走看看