Codeforces 828 C String Reconstruction
2017-07-13 20:02
323 查看
题目地址:http://codeforces.com/contest/828/problem/C
题意:给你一些字符串的提示,让你拼接出一个完整的字典序最小的字符串(PS:是一定会有字符串的,所以重复的可以不用去看,因为一定是对的,我就是一开始没看懂这个TLE了)
思路:把起点的顺序排序,再遍历。重复的就不用考虑,详细看代码,比较容易理解,仔细点就好了
题意:给你一些字符串的提示,让你拼接出一个完整的字典序最小的字符串(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 ; 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; }
相关文章推荐
- codeforces 828 c String Reconstruction(扫描线+string)
- Codeforces 710 E. Generate a String (dp)
- codeforces 128B - String
- Codeforces 868 D Huge String
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
- Codeforces 877(442 Div.2) B. Nikita and string
- Codeforces 632C The Smallest String Concatenation 【string】
- CodeForces-710E Generate a String(DP)
- 【codeforces 709D】Recover the String
- codeforces 128 B. String 优先队列
- codeforces 676C C. Vasya and String 尺取法
- CodeForces 632C - C. The Smallest String Concatenation
- CodeForces 219A k-String
- Codeforces 624C:Graph and String 二分图染色
- codeforces_672A. Summer Camp(string)
- codeforces 709D Recover the String (构造+模拟)
- CodeForces-632C-The Smallest String Concatenation
- codeforces 710E Generate a String(dp)
- CodeForces 733A - Grasshopper And the String
- 【Educational Codeforces Round 16】 Codeforces 710E Generate a String