题目地址:http://codeforces.com/contest/828/problem/C
题意:给你一些字符串的提示,让你拼接出一个完整的字典序最小的字符串(PS:是一定会有字符串的,所以重复的可以不用去看,因为一定是对的,我就是一开始没看懂这个TLE了)
思路:把起点的顺序排序,再遍历。重复的就不用考虑,详细看代码,比较容易理解,仔细点就好了
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long
#define N 10000010
#define M 50010
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
string str[N];
struct node {
int id, x;
}now;
vector<node>v;
bool cmp(node a, node b) {
if (a.x == b.x) {
return str[a.id].length() > str[b.id].length();
}
return a.x < b.x;
}
int main() {
cin.sync_with_stdio(false);
int n, m;
while (cin >> n) {
v.clear();
for (int i = 0; i < n; i++) {
cin >> str[i] >> m;
now.id = i;
for (int j = 0; j < m; j++) {
cin >> now.x;
v.push_back(now);
}
}
sort(v.begin(), v.end(), cmp);
int len = v.size();
int num = 1;
for (int i = 0; i < len; i++) {
while (num < v[i].x) {
num++;
cout << "a";
}
if (num != v[i].x) {
if (num > v[i].x + str[v[i].id].length()) {
continue;
}
for (int j = num - v[i].x; j < str[v[i].id].length(); j++) {
cout << str[v[i].id][j];
num++;
}
}
else {
cout << str[v[i].id];
num += str[v[i].id].length();
}
}
cout << endl;
}
return 0;
}