Zhejiang Institute of Science and Technology 13th session of the program Design competition 1001:let's go to play careful

Source: Internet
Author: 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 DescriptionMr.lin would a party and invite he friends to the 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, the number of male friends should equal to the number of femal friends. InputMultiple sets of test data.

The first line of all 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-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.
OutputPrint The maximum number of people. Sample Input
4
M 151 307
F 343 352
F 117 145
M 6 m (mm)
F 131
F 131 +
F 131 141
  m 131
M 140 200
Sample Output
2
4
Ac-code:
#include <stdio.h>
#include <cstring>
using namespace std;
int main ()
{
	int n,i,j,f[370],m[370],st,ed,max;
	char c;
	while (~SCANF ("%d", &n))
	{
		memset (f,0,sizeof (f));
		memset (M,0,sizeof (m));
		for (i=0;i<n;i++)
		{
			getchar ();
			scanf ("%c", &c);
			scanf ("%d%d", &st,&ed);
			if (st>ed)
				j=st,st=ed,ed=j;
			if (c== ' F ') for
				(j=st;j<=ed;j++)
					f[j]++;
			else for
				(j=st;j<=ed;j++)
					m[j]++;
		}
		max=0;
		for (i=1;i<=366;i++)
			if (F[i]>max&&m[i]>max)
				max=f[i]>m[i]?m[i]:f[i];
		printf ("%d\n", 2*max);
	}
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.