PAT《团体设计天梯赛》2021

Problem L3-029 还原文件 (30 分)


应 该 算 是 一 道 模 板 题 目 了 , 字 符 串 h a s h + d f s 匹 配 应该算是一道模板题目了,字符串hash+dfs匹配 hash+dfs
建议背下来

/*Love coding and thinking!*/ 
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <vector>
#define pb push_back 
#define mem(f, x) memset(f,x,sizeof(f)) 
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo2(i,a,n) for(int i=(a);i<(n);++i)
#define debug(x) cout<<#x<<":"<<x<<endl;
#define endl '\n'
using namespace std;
typedef pair<int,int>PII;
typedef pair<long,long>PLL;

typedef long long ll;
typedef unsigned long long ull; 
const int N=1e5+10,M=110,P=131;
int n,m,_;

ull g[N],p[N];//长版的hash
ull Hash[M];//每个小长条的hash
int width[M];
int ans[M];
bool st[M];//判重数组
int x;
ull get(int l,int r)//返回区间hash值
{
	return g[r]-g[l-1]*p[r-l+1];
}

bool dfs(int u,int ed)//第u个长条能不能拼接上,上一个的结尾是ed
{
	if(ed==n)
	{
		return true;	
	}
	
	for(int i=1;i<=m;i++)
	{
		if(!st[i]&&Hash[i]==get(ed,ed+width[i]-1))
		{
			st[i]=1;
			ans[u]=i;
			if(dfs(u+1,ed+width[i]-1))
				return 1;	
			st[i]=0;
		}
	}
	return false;
}
int main()
{
	cin>>n;
	p[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		p[i]=p[i-1]*P;//只在得到区间hash值时用到
		g[i]=g[i-1]*P+x+1;//一般都是*P,注意区分,因为0、00的会重复,所以从1开始
	}
	cin>>m;
	
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&width[i]);
		for(int j=0;j<width[i];j++)
		{
			scanf("%d",&x);
			Hash[i]=Hash[i]*P+x+1;
		}
	}
	dfs(1,1);
	for(int i=1;i<=m;i++)
		if(i!=m)
			printf("%d",ans[i]);
		else
			printf("%d ",ans[i]);

	return 0;
}

### 团体程序设计天梯赛练习与在线评测系统 团体程序设计天梯赛提供了一个全面的练习平台,参赛者可以在PAT (Programming Ability Test)网站上找到丰富的练习资源[^1]。该竞赛旨在通过一系列具有挑战性的编程问题来评估团队和个人的能力。 #### 在线评测系统的特色 - **广泛覆盖**:提供了大量的练习题目,涵盖了不同难度级别,适合各个层次的学习者。 - **即时反馈**:提交代码后能够立即获得运行结果和评分情况,帮助快速定位并修正错误。 - **模拟环境**:创建真实的比赛场景,使参与者熟悉正式考试流程,减少紧张感。 - **社区交流**:拥有活跃的技术讨论区,可以与其他程序员分享经验、解决问题。 对于希望参加团体程序设计天梯赛的人来说,在线评测系统不仅是一个有效的训练工具,也是一个提升技能的好地方。它允许用户按照自己的节奏学习和发展,同时准备应对实际比赛中可能遇到的各种挑战[^2]。 ```python # 示例:如何连接到PAT在线评测系统进行登录操作(伪代码) import requests def login_to_pat(username, password): url = "https://www.patest.cn/users/sign_in" payload = { &#39;user[login]&#39;: username, &#39;user[password]&#39;: password } session = requests.Session() response = session.post(url, data=payload) if response.status_code == 200: print("Login successful!") else: print("Failed to log in.") # 使用方法 login_to_pat(&#39;your_username&#39;, &#39;your_password&#39;) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值