码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 777D:Cloud of Hashtags(水题)

时间:2017-02-26 20:51:20      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:name   com   字符串   思路   tar   log   include   大于   style   

http://codeforces.com/problemset/problem/777/D

题意:给出n道字符串,删除最少的字符使得s[i] <= s[i+1]。

思路:感觉比C水好多啊,大概是题目比较难看懂吧。直接从后面往前扫,用后面的答案更新前面的答案。考虑如果后面的字符串比前面的大,那么直接保存当前的字符串,否则暴力扫一遍,前面的字符串大于后面的字符串的那一位直接跳出。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 string s[500010];
 4 string ans[500010];
 5 int main() {
 6     int n;
 7     scanf("%d", &n);
 8     for(int i = 1; i <= n; i++) cin >> s[i];
 9     ans[n] = s[n];
10     for(int i = n - 1, j; i >= 1; i--) {
11         if(ans[i+1] >= s[i]) { ans[i] = s[i]; continue; }
12 
13         int a = s[i].size(), b = ans[i+1].size();
14         int len = min(a, b);
15         for(j = 0; j < len; j++)
16             if(s[i][j] > ans[i+1][j]) break;
17         for(int k = 0; k < j; k++) ans[i] += s[i][k];
18     }
19     for(int i = 1; i <= n; i++) cout << ans[i] << endl;
20     return 0;
21 }

 

Codeforces 777D:Cloud of Hashtags(水题)

标签:name   com   字符串   思路   tar   log   include   大于   style   

原文地址:http://www.cnblogs.com/fightfordream/p/6445559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!