#423 Div2 C

题意

给出 n 个字符串以及他们在 S 串中出现的位置,求字典序最小的 S 串。保证给出的字符串不会冲突。

分析

模拟就好。用并查集思想优化,数组 nxt[i] 表示从 i 开始 接下来还未填字母的第一个位置。初始化 nxt[i] = i

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
const int N = 2e6 + 10;
char str[N], s[N];
int nxt[N];
int fd(int x) {
return x == nxt[x] ? x : (nxt[x] = fd(nxt[x]));
}
int main() {
for(int i = 0; i < N; i++) {
nxt[i] = i;
}
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s", s);
int len = strlen(s);
int c;
scanf("%d", &c);
for(int j = 0; j < c; j++) {
int x;
scanf("%d", &x);
x--;
int l = len;
int pos = 0;
int nxt_x = fd(x);
while(nxt_x - x < l) {
pos = nxt_x - x;
str[nxt_x] = s[pos];
nxt[nxt_x] = fd(nxt_x + 1);
nxt_x = nxt[nxt_x];
}
}
}
int ii = -1;
for(int i = N - 1; i >= 0; i--) {
if(str[i] >= 'a' && str[i] <= 'z') {
if(ii == -1) ii = i + 1;
} else {
str[i] = 'a';
}
}
if(ii == -1) ii = 0;
str[ii] = 0;
printf("%s\n", str);
return 0;
}

最新文章

  1. ABP(现代ASP.NET样板开发框架)系列之23、ABP展现层——异常处理
  2. 从零自学Hadoop(08):第一个MapReduce
  3. 如何在本地搭建IIS服务器
  4. Win10 Theano Install Guide
  5. android蓝牙技术
  6. js 与或运算符 || &amp;&amp; 妙用(转)
  7. PLSQL Developer调试 存储过程和触发器
  8. Web站点错误提示页面和默认访问页面设置
  9. git程序多版本维护方案
  10. SoapUI并发模式
  11. View体系第二篇:View滑动
  12. Go语言变量和常量
  13. sql语句修改字段约束为不为空 并为其设置主键
  14. cacti监控服务器
  15. jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件[自主开发]
  16. Masonry基本语法
  17. 用MVC5+EF6+WebApi 做一个小功能(二) 项目需求整理
  18. python3: 数字日期和时间(1)
  19. Android P 功能和 API
  20. windows操作系统查看占用端口的进程

热门文章

  1. (原、整)BSP的江湖传说
  2. Node rescue/unrescue相关代码流程图
  3. ironic state information
  4. centos6 install cobbler
  5. Python namedtuple(命名元组)使用实例
  6. Opencv3.3.1安装包
  7. springboot07 mysql02
  8. CodeForces D. Concatenated Multiples
  9. deeplearning4j——卷积神经网络对验证码进行识别
  10. [poj] 3690 Constellations || 矩阵hash