Codeforces 777D:Cloud of Hashtags(水题)
http://codeforces.com/problemset/problem/777/D
题意:给出n道字符串,删除最少的字符使得s[i] <= s[i+1]。
思路:感觉比C水好多啊,大概是题目比较难看懂吧。直接从后面往前扫,用后面的答案更新前面的答案。考虑如果后面的字符串比前面的大,那么直接保存当前的字符串,否则暴力扫一遍,前面的字符串大于后面的字符串的那一位直接跳出。
#include <bits/stdc++.h>
using namespace std;
string s[];
string ans[];
int main() {
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) cin >> s[i];
ans[n] = s[n];
for(int i = n - , j; i >= ; i--) {
if(ans[i+] >= s[i]) { ans[i] = s[i]; continue; } int a = s[i].size(), b = ans[i+].size();
int len = min(a, b);
for(j = ; j < len; j++)
if(s[i][j] > ans[i+][j]) break;
for(int k = ; k < j; k++) ans[i] += s[i][k];
}
for(int i = ; i <= n; i++) cout << ans[i] << endl;
return ;
}
Codeforces 777D:Cloud of Hashtags(水题)的更多相关文章
- Codeforces 777D Cloud of Hashtags(贪心)
题目链接 Cloud of Hashtags 题目还是比较简单的,直接贪心,但是因为我有两个细节没注意,所以FST了: 1.用了cin读入,但是没有加 std::ios::sync_with_stdi ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- ADT eclipse的几个快捷键
智能内容感知 Alt+/ ,该快捷键可以方便的匹配我们使用的类信息,/ 在键盘上和?是同一个按键. ctrl+.及ctrl+1:下一个错误及快速修改 ctrl+.将光标移动至当前文件中的下一个报错处或 ...
- jquery hover()的使用
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- wpf中防止界面卡死的写法
原文:wpf中防止界面卡死的写法 ); this.Dispatcher.BeginInvoke(new Action(() => { this.button1.Content = "计 ...
- WPF下Itemscontrol分组 样式
原文 WPF下Itemscontrol分组 样式 <ItemsControl Grid.Row="1" DataContext="{Binding Layouts} ...
- HTTP协议入门(一)- 版本
当我们在浏览器的地址栏输入URL后,信息会被发送到WEB服务器,服务器得到响应,将数据传输回来,展示到WEB页面上,这其中的传输方法就是HTTP协议. 一.HTTP 0.9 发布于1991年,是首个H ...
- SpringBoot简易搭建
1.建立maven工程 2.打开pom文件, 将以下配置拷贝过去 <parent> <groupId>org.springframework.boot</groupId& ...
- 图像滤镜艺术----Brannan滤镜
原文:图像滤镜艺术----Brannan滤镜 作为第一篇文章,本人将介绍Instagram中Brannan 滤镜的实现过程,当然,是自己的模拟而已,结果差异敬请谅解. 先看下效果图: ...
- 还可以使用Q_SIGNAL,Q_EMIT,Q_SLOT避免第三方库的关键字冲突
You can define the QT_NO_KEYWORDS macro, that disables the “signals” and “slots” macros. If you use ...
- 设置windows2008系统缓存大小限制,解决服务器运行久了因物理内存耗尽出僵死(提升权限后,使用SetSystemFileCacheSize API函数,并将此做成了一个Service)
声明: 找到服务器僵死的原因了,原因是虚拟内存设置小于物理内存. 只要虚拟内存设置为系统默认大小就不会出生僵死的现象了. 当时因为服务器内存48G,系统默认虚拟内存大小也是48G, 觉得太占硬盘空间, ...
- How Qt Signals and Slots Work(感觉是通过Meta根据名字来调用)
Qt is well known for its signals and slots mechanism. But how does it work? In this blog post, we wi ...