#423 Div2 C
2024-09-04 17:41:30
#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;
}
最新文章
- ABP(现代ASP.NET样板开发框架)系列之23、ABP展现层——异常处理
- 从零自学Hadoop(08):第一个MapReduce
- 如何在本地搭建IIS服务器
- Win10 Theano Install Guide
- android蓝牙技术
- js 与或运算符 || &;&; 妙用(转)
- PLSQL Developer调试 存储过程和触发器
- Web站点错误提示页面和默认访问页面设置
- git程序多版本维护方案
- SoapUI并发模式
- View体系第二篇:View滑动
- Go语言变量和常量
- sql语句修改字段约束为不为空 并为其设置主键
- cacti监控服务器
- jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件[自主开发]
- Masonry基本语法
- 用MVC5+EF6+WebApi 做一个小功能(二) 项目需求整理
- python3: 数字日期和时间(1)
- Android P 功能和 API
- windows操作系统查看占用端口的进程
热门文章
- (原、整)BSP的江湖传说
- Node rescue/unrescue相关代码流程图
- ironic state information
- centos6 install cobbler
- Python namedtuple(命名元组)使用实例
- Opencv3.3.1安装包
- springboot07 mysql02
- CodeForces D. Concatenated Multiples
- deeplearning4j——卷积神经网络对验证码进行识别
- [poj] 3690 Constellations || 矩阵hash