HDU Let's go to play

yao1373446012 · · 1851 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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

4
M 151 307
F 343 352
F 117 145
M 24 128
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 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;
 } 



有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:yao1373446012

查看原文:HDU Let's go to play

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1851 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传