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 }
    ——将来的你会感谢现在努力的自己。
  • 相关阅读:
    Java实现批量下载《神秘的程序员》漫画
    mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法
    opencv学习_15 (利用cmake查看opencv的源码)
    jobs 命令
    中断子系统6_中断嵌套处理
    JPA一对多映射
    JPA Map映射
    JPA集合映射
    JPA删除实体
    JPA查找实体
  • 原文地址:https://www.cnblogs.com/yexiaozi/p/5697943.html
Copyright © 2011-2022 走看看