E. Email Destruction---大模拟

博客围绕邮箱邮件问题展开,黑客攻击邮箱致部分邮件删除,已知剩余邮件情况,猜测原邮件数为n,需判断猜测是否正确。邮件呈链式,主题有特定规律。关键在于数据处理,给出了判断思路,最后还分享了AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Email Destruction

Time Limit: 3 Sec Memory Limit: 512 Mb

题目链接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”.


emmm,题目大意,黑客攻击了你的邮箱,删去了一部分邮件,你猜你的邮箱原邮件数为n,判断是否正确。这些邮件的特点是链式的:即第一个主题如果为W则不变,下一个与之一样主题的需要重复一遍:Re: W,第三一样的就Re: Re: W依次类推(注意:后有空格)。

要使得猜到的正确,则n必须大于等于现有已知的邮件数,实际我们只需要标记一下就行了,也就是求每个主题Re的最大值+1,然后将每个主题的最大值加上就是当下已知的最大值,只要n>=该值就是Ok的。

但关键是数据的处理有点麻烦,我用string比较方便一点。。。当然,当时比赛的时候数据有点毒瘤。。。开头两个整数之后还有一个空格。。。到时getchar()一次的WA到死。。。而很不幸的是我就是这一撮人中的一个。。。最后十几分钟的时候多加了一个getchar()就过了。。。

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
char s[600];
string tp[600];
map<string,int>q;
int main()
{
	int n,ans=0,k,tot=1;
	scanf ("%d%d",&n,&k);
	getchar();
	getchar();
	for (int i=1; i<=k; i++){
		gets(s);
		int len=strlen(s);
		if (s[0]!='R') {
			for (int j=0; j<len; j++) tp[tot]+=s[j];
			int p=q[tp[tot]];
			q[tp[tot]]=max(p,1);		
			tot++;
			if (i==k) break;
			else continue;
		}
		int cnt=0;
		for (int j=0; j<len; j++){
			if (s[j]=='R') {
				cnt++; j+=3;
			}
			else {
				cnt++;
				for (int kk=j; kk<len; kk++) tp[tot]+=s[kk];
		    	int p=q[tp[tot]];		
				q[tp[tot]]=max(p,cnt);
				tot++;
				break;
			}
		}	
	}
	sort(tp+1,tp+tot);
	string kw="------";
	for (int i=1; i<tot; i++){
		if (tp[i]!=kw) {
			ans+=q[tp[i]];
			kw=tp[i];
		}
	}
	if (ans<=n) printf ("YES\n");
	else printf ("NO\n");
	return 0;
}
### 3.1 确认 MySQL JDBC 驱动是否正确加载 Seata Server 在启动时依赖 MySQL JDBC 驱动文件(如 `mysql-connector-java-8.0.30.jar`)来连接数据库。该驱动文件必须放置在 `lib/jdbc` 目录下,并且确保路径为纯英文,避免因路径包含中文导致驱动加载失败 [^1]。 使用解压工具打开驱动 JAR 文件,检查 `META-INF/services/java.sql.Driver` 文件中是否包含 `com.mysql.cj.jdbc.Driver`。该文件用于定义 JDBC 驱动的自动加载机制。如果文件缺失或内容不完整,需要更换一个完整的 MySQL JDBC 驱动包。 ### 3.2 验证 application.yml 中的数据库配置 在 Seata Server 的 `application.yml` 文件中,需要正确配置数据库驱动类名、连接 URL、用户名和密码。错误的配置会导致启动失败。以下是一个示例配置: ```yaml spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: 123456 ``` 确保 `driver-class-name` 指定的类名与驱动文件中的实现一致,并且数据库连接 URL 格式正确。如果使用的是 MySQL 8.x 版本,需要添加 `serverTimezone=Asia/Shanghai` 参数以避免时区问题 [^1]。 ### 3.3 检查 Seata 服务的 registry.conf 或 application.yml 除了 `application.yml` 外,Seata 的配置文件还包括 `registry.conf` 或 `seataServer.properties`,用于定义事务组和服务组的映射关系。例如: ```properties service.vgroupMapping.my_test_tx_group = default ``` 如果缺少 `vgroupMapping` 配置项,或者配置的事务组名称与客户端使用的不一致,会导致 Seata 无法正确连接到事务协调器。需要检查 `registry.conf` 或 `seataServer.properties` 中的 `service.vgroupMapping` 配置项是否正确 [^2]。 ### 3.4 确保 Java 环境兼容 MySQL JDBC 驱动 MySQL Connector/J 8.x 要求使用 Java 8 或更高版本。如果运行 Seata Server 的 Java 环境版本过低,可能导致驱动无法加载。可以通过以下命令检查 Java 版本: ```bash java -version ``` 如果版本低于 1.8,则需要升级 JDK 并重新配置环境变量。 ### 3.5 清理缓存并重启服务 有时旧的缓存可能影响驱动加载。尝试删除 Seata Server 的 `logs` 目录下的日志文件和 `store` 目录下的持久化数据,然后重新启动服务。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值