HDU Let's go to play

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Let's go to play

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 773   Accepted Submission(s) : 213

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Mr.Lin would like to hold a party and invite his friends to this party. He has n friends and each of them can come in a specific range of days of the year from ai to bi.
Mr.Lin wants to arrange a day, he can invite more friends. But he has a strange request that the number of male friends should equal to the number of femal friends.

Input

Multiple sets of test data.

The first line of each input contains a single integer n (1<=n<=5000 )

Then follow n lines. Each line starts with a capital letter 'F' for female and with a capital letter 'M' for male. 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.

Sample Input

4M 151 307F 343 352F 117 145M 24 1286M 128 130F 128 131F 131 140F 131 141M 131 200M 140 200

Sample Output

2

4

看到這道題一直想著怎麼用貪心。。。。看到別人的題解後才恍然大悟,類比一下就行了。

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int f[50050],m[50050];int main(){int n,i,j,k,l;while(scanf("%d",&n)!=EOF){memset(f,0,sizeof(f));memset(m,0,sizeof(m));int x,y;char t;for(i=0;i<n;i++){getchar();scanf("%c%d%d",&t,&x,&y);if(t=='M'){    for(j=x;j<=y;j++)    m[j]++;}    else    {    for(j=x;j<=y;j++)    f[j]++;}}int ans=0;for(i=1;i<=366;i++){int minn=min(m[i],f[i]);ans=max(2*minn,ans);}printf("%d\n",ans);}return 0; } 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.