CSU 2312 模拟

http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2312

Description

You have an account on ICPCorrespondence.com. This is an email service where emails are grouped into chains by their subject as follows.

The first email in every chain has a non-empty subject consisting of lowercase English letters. Every succeeding email in the chain has a subject consisting of "Re: " followed by the subject of the previous email.

For example, if the first email in the chain has subject "subj", then the second email has subject "Re: subj", the third one has subject "Re: Re: subj", and so on. Formally, the subject of the k-th email in the chain consists of "Re: " repeated k − 1 times followed by the subject of the first email in the chain.

In your mailbox, you had one or more chains of emails with unique subjects. You never removed any emails from your mailbox.

Unfortunately, one day ICPCorrespondence.com was attacked by hackers. As a result of this attack, some emails were removed from the server, while the remaining emails were shuffled.

You are not sure how many emails you had in the mailbox before the attack, but you guess that this number is n. Can you check whether this guess can be correct?

Input

The first line of the input contains two integers n and k --- the number of emails that you think were in the mailbox before the attack, and the number of emails left after the attack, respectively (1 ≤ k ≤ n ≤ 100).

The following k lines contain subjects of the emails left in your mailbox, one per line. The subject of each email consists of "Re: " repeated zero or more times, followed by at least one and no more than 10 lowercase English letters. The length of each subject does not exceed 500. All email subjects are pairwise distinct.

Output

If your guess about the number of emails in your mailbox prior to the attack can be correct, output a single word "YES". Otherwise, output a single word "NO".

Sample Input

7 3
Re: Re: Re: hello
Re: world
hello

Sample Output

YES

Hint

In the first example, the guess can be correct. For example, you could have emails with subjects "hello", "Re: hello", "Re: Re: hello", "Re: Re: Re: hello", "Re: Re: Re: Re: hello", "world", and "Re: world".

In the second example, the guess is incorrect since there had to be at least three emails in the chain of "pleasehelp" and at least one email in the chain of "me".

简单模拟题,别的不想说。格式毒瘤,\r\n,然后就一直WA一直爽。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;

map<string,int> mymap;
string s;
int n,m;
int tot=0;

int main()
{
	while(~scanf("%d%d\n",&n,&m))
	{
		tot=0;
		mymap.clear();
		string temp;
		for(int i=0;i<m;i++)
		{
			getline(cin,temp);
			stringstream ss(temp);
			int cnt=1;
			while(ss>>s)
			{
				//cout<<s<<endl;
				if(s=="Re:")
					++cnt;
				else
					mymap[s]=max(mymap[s],cnt);
			}
		}
		map<string,int> ::iterator it=mymap.begin();
		for(;it!=mymap.end();it++)
			tot+=it->second;
		if(tot<=n)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/xiji333/article/details/89760632