Codeforces - 828C String Reconstruction —— 并查集find()函数

题目链接:http://codeforces.com/contest/828/problem/C

 

C. String Reconstruction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.

Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.

You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.

The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings ti doesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.

It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

Output

Print lexicographically minimal string that fits all the information Ivan remembers.

Examples
input
Copy
3
a 4 1 3 5 7
ab 2 1 5
ca 1 4
output
Copy
abacaba
input
Copy
1
a 1 3
output
Copy
aaa
input
Copy
3
ab 1 1
aba 1 3
ab 2 3 5
output
Copy
ababab

 

题意:

求一个字典序最小的字符串,满足若干个字符串在此字符串中的出现情况。

采取逐个位置写入的方法。为了避免超时,写过的位置就不能重新写,而需找到后面第一个没有被写入的位置。那如果找到这个位置呢?如果直接往后遍历,那就跟重复写入没有区别了,所以,我们需要一个快速找到后面第一个没有被写入的位置的方法,可用并查集的find()函数。灵感来源:POJ1456 Supermarket 。

 

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <cstdlib>
 6 #include <string>
 7 #include <vector>
 8 #include <map>
 9 #include <set>
10 #include <queue>
11 #include <sstream>
12 #include <algorithm>
13 using namespace std;
14 typedef long long LL;
15 const double eps = 1e-8;
16 const int INF = 2e9;
17 const LL LNF = 9e18;
18 const int MOD = 1e9+7;
19 const int MAXN = 2e6+10;
20 
21 int fa[MAXN];   //fa[]用于记录此位置后面第一个没有被写入位置
22 bool used[MAXN];
23 int find(int x)
24 {
25     return !used[x]?x:fa[x]=find(fa[x]);
26 }
27 
28 char s[MAXN], tmp[MAXN];
29 int main()
30 {
31     int n;
32     while(scanf("%d",&n)!=EOF)
33     {
34         memset(s, 0, sizeof(s));
35         memset(used, 0, sizeof(used));
36         for(int i = 1; i<MAXN-1; i++)
37             fa[i] = i+1;
38         for(int i = 1; i<=n; i++)
39         {
40             scanf("%s",tmp);
41             int sz = strlen(tmp);
42             int m, x;
43             scanf("%d",&m);
44             while(m--)
45             {
46                 scanf("%d",&x);
47                 for(int i = 0; i<sz;)
48                 {
49                     if(!s[x+i]) //此位置没有被写入,则填写
50                     {
51                         s[x+i] = tmp[i];
52                         used[x+i] = 1;
53                         i++;
54                     }
55                     else i = find(x+i)-x;   //否则,找到后面位置第一个没有被写入的相对位置
56                 }
57             }
58         }
59 
60         int sz = MAXN-1;
61         while(!s[sz]) sz--;
62         for(int i = 1; i<=sz; i++)
63         {
64             if(s[i]==0) putchar('a');   //把没有写入的位置都填上‘a’
65             else putchar(s[i]);
66         }
67         putchar('\n');
68     }
69 }
View Code

 

 

转载于:https://www.cnblogs.com/DOLFAMINGO/p/8909589.html

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值