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

Codeforces 777D Cloud of Hashtags(贪心)

时间:2017-02-26 11:15:13      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:ret   经验   简单   clu   blog   com   int   style   fst   

题目链接 Cloud of Hashtags

题目还是比较简单的,直接贪心,但是因为我有两个细节没注意,所以FST了:

1、用了cin读入,但是没有加 std::ios::sync_with_stdio(false); 这条语句;

2、开了太多string。

也算是经验教训吧。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define rep(i, a, b)              for(int i(a); i <= (b); ++i)
 6 #define dec(i, a, b)              for(int i(a); i >= (b); --i)
 7 
 8 const int N     =    500000      +       10;
 9 int n;
10 string s[N], c[N];
11 
12 int main(){
13 
14     std::ios::sync_with_stdio(false);
15     cin >> n;
16     rep(i, 1, n) cin >> s[i];
17     c[n] = s[n];
18     dec(i, n - 1, 1){
19         int j = i + 1;
20         if (s[i] <= c[j]){
21             c[i] = s[i];
22             continue;
23         }
24         int l1 = s[i].length(), l2 = c[j].length();
25         int p;
26         rep(k, 1, l1 - 1){
27             if (s[i][k] > c[j][k] || k > l2 - 1){
28                 p = k - 1;
29                 break;
30             }
31         }
32 
33         c[i] = "";
34         rep(k, 0, p) c[i] = c[i] + s[i][k]; 
35     }
36 
37     rep(i, 1, n) cout << c[i] << endl;
38 
39 
40     return 0;
41 
42 }

 

Codeforces 777D Cloud of Hashtags(贪心)

标签:ret   经验   简单   clu   blog   com   int   style   fst   

原文地址:http://www.cnblogs.com/cxhscst2/p/6443685.html

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