zoukankan      html  css  js  c++  java
  • Far Relative’s Problem (贪心 计算来的最多客人)

    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

    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

    Hint

    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 int wom[400],man[400],n,max= 0,x,y;  
     3 char c;    
     4 int main()  
     5 {  
     6     scanf("%d",&n);  
     7     for(int i = 0;i<n;i++)  
     8     {  
     9         scanf("%s %d %d",&c,&x,&y);  
    10         if(c == 'M')  
    11         {  
    12             for(int i = x;i<=y;i++)  
    13             {  
    14                 man[i]++;  
    15             }  
    16         }  
    17         else  
    18         {  
    19             for(int i = x;i<=y;i++)  
    20             {  
    21                 wom[i]++;  
    22             }  
    23         }  
    24     }  
    25     for(int i = 0;i<=370;i++)  
    26     {  
    27         if(max < (wom[i]<man[i]?wom[i]:man[i])*2)  
    28         {  
    29             max = 2*(wom[i]<man[i]?wom[i]:man[i]);  
    30         }  
    31     }  
    32    printf("%d
    ",max); 
    33 }
    ——将来的你会感谢现在努力的自己。
  • 相关阅读:
    sql 随机获取100条数据
    NPOI导出信息
    JavaScript打印页面
    生僻字在页面上不显示(䶮)
    C# 下载文件并使用指定名称展示
    layui 表格列编辑获取编辑前的值然后重新赋值,并通过键盘控制编辑位置
    C# 网络图片转base64
    C# WebApi debug模式下编译没有问题,切换到release模式下编译就有异常,但是依旧能生成成功,再切回到debug模式也会报错,也可以生成成功
    HTTP/2
    Class的继承
  • 原文地址:https://www.cnblogs.com/yexiaozi/p/5697943.html
Copyright © 2011-2022 走看看