【题目链接】:http://codeforces.com/contest/777/problem/D

【题意】

让你通过删除字符串的末尾字符的方式;

使得所给的字符串以字典序升序排序;

不能交换字符串之间的位置;

【题解】

/*
要求字符串的字典序升序排;
不能交换字符串的位置;
那就使得
s[i]<=s[i+1]对i∈[1..n-1]都成立就好;
(这里的<=指的是字典序的小于等于);
从最后一个字符串开始;
逆序处理字符串1..n-1;
对比字符串s[i]和s[i+1]的所有字符;
对比的时候len = min(s[i].size(),s[i+1].size());
找到第一个字符不一样的位置pos;
如果找到了这样一个pos;
记录它
if (s[i][pos]<s[i+1][pos])
则这个字符串出现在这里是合法的;
符合s[i]<=s[i+1]
if (s[i][pos]>s[i+1][pos])
则把s[i]从pos开始全部删掉;
然后处理下一个; 当然,如果pos没有找到的话,就比较s[i].size()和s[i+1].size();
如果s[i].size()<=s[i+1].size();则合法
否则从s[i].size()+1开始把s[i]从s[i].size()+1一直到结束全部删掉
(可以不用真的删掉吧。写一个to[n];
表示每个字符串输出的时候要一直输出到哪个地方.
*/

【完整代码】

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 5e5 + 100; string s[N];
int n;
int to[N];
bool bo[N]; int main()
{
//读入优化??
//freopen("D:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
cin >> s[i];
int len = s[n].size();
len--;
to[n] = len;
rep2(i, n - 1, 1)
{
int len = min(to[i + 1], int(s[i].size())-1);
int pos = -1;
rep1(j,1,len)
if (s[i][j] != s[i + 1][j])
{
pos = j;
break;
}
if (pos != -1)
{
if (s[i][pos] < s[i + 1][pos])
{
to[i] = int(s[i].size())-1;
continue;
}
if (s[i][pos] > s[i + 1][pos])
{
to[i] = pos - 1;
continue;
}
}
if (int(s[i].size()) <= to[i + 1])
{
to[i] = int(s[i].size())-1;
continue;
}
to[i] = to[i + 1];
}
rep1(i, 1, n)
{
putchar('#');
rep1(j, 1, to[i])
putchar(s[i][j]);
puts("");
}
return 0;
}

【codeforces 777D】Cloud of Hashtags的更多相关文章

  1. Codeforces 777D:Cloud of Hashtags(水题)

    http://codeforces.com/problemset/problem/777/D 题意:给出n道字符串,删除最少的字符使得s[i] <= s[i+1]. 思路:感觉比C水好多啊,大概 ...

  2. Codeforces 777D:Cloud of Hashtags(暴力,水题)

    Vasya is an administrator of a public page of organization "Mouse and keyboard" and his ev ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. C#集合类:动态数组、队列、栈、哈希表、字典

    1.动态数组:ArrayList 主要方法:Add.AddRange.RemoveAt.Remove 2.队列:Queue 主要方法:Enqueue入队列.Dequeue出队列.Peek返回Queue ...

  2. JPA的配置文件persistence.xml参数详解

    <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0&q ...

  3. 洛谷—— P1967 货车运输 || COGS——C 1439. [NOIP2013]货车运输

    https://www.luogu.org/problem/show?pid=1967#sub  ||  http://www.cogs.pro/cogs/problem/problem.php?pi ...

  4. JQuery EasyUI Combobox 实现省市二级联动菜单

    //编辑改动或新增页面联动能够这样写 jQuery(function(){ // 省级 $('#province').combobox({ valueField:'itemvalue', //值字段 ...

  5. JS实现动画方向切换效果(包括:撞墙反弹,暂停继续左右运动等)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. Django中pycharm中 报错 ---ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'system.sysuser', bu

    问题是:已经在settings.py文件中注册过app仍旧提示没有安装,并且使用makegirations命令时会抛出如下异常 解决方法: 找到自己的python3.x,进入site-packages ...

  7. 1、移动端 2、后台 3、 移动端,Web 端 4、 PC端

    移动端: 1.公众号:停开心 住总物业 2.app:  iso Android 停开心,住总停开心 后台:停开心智慧停车管理平台(所有的停车场) 移动端,Web端: 海投OA,公司OA PC端:收费软 ...

  8. 国密算法SM2证书制作

    国密算法sm2非对称算法椭圆曲线 原文:http://www.jonllen.cn/jonllen/work/162.aspx 前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件 ...

  9. 如何获取用户的地理位置-浏览器地理位置(Geolocation)API 简介

    如何获取用户的地理位置-浏览器地理位置(Geolocation)API 简介 一.总结 一句话总结:Geolocation API(地理位置应用程序接口)提供了一个可以准确知道浏览器用户当前位置的方法 ...

  10. shiro 中的filterChainDefinitions详解(转)

    springrain使用shiro控制权限,配置filterChainDefinitions结合数据库校验权限. 我们在web.xml中配置一个全局过滤器,也就是在springrain配置的是一个sp ...