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 ...
随机推荐
- ThreadPoolExecutor原理和使用
大家先从ThreadPoolExecutor的整体流程入手: 针对ThreadPoolExecutor代码.我们来看下execute方法: public void execute(Runnable c ...
- linq to entity GroupBy多个字段
var items = _voteRecordRepository.GetAll() .Where(x => programIds.Contains(x.ProgrammeId)) .Group ...
- 自定义View实现图片热区效果
我司主要从事工业物联网领域软件的开发,现有个需求,在外废品处理时需要对产品的不良位置进行标记,点选图片实现图片网格的着色功能. 需求是通过自定义view来实现,实现思路如下: 首先将点击的小方格对象实 ...
- miniui autocomplete支持放大镜按钮(data-grid)
<style type="text/css"> html body .searchbox .mini-buttonedit-close { background:url ...
- 微信小程序把玩(十)swiper组件
原文:微信小程序把玩(十)swiper组件 Android写过轮播图的痛楚只有写过的知道,相对还是比较麻烦的,并没有一个轮播图组件,有个ViewPage也需要自己定制,IOS则多用UIScroller ...
- ubuntu 16.04 android studio 开发环境搭建
安装步骤: 1. 安装 Java developer kit 2.安装 Android developer kit 3.安装 Android studio 4.真机调试 第一次用Linux,命令基本不 ...
- Flot Reference flot参考文档
Consider a call to the plot function:下面是对绘图函数plot的调用: var plot = $.plot(placeholder, data, options) ...
- jQuery简明教程
本文参考w3cshool中文教程,网址:http://www.w3school.com.cn/jquery/index.asp 简介 jQuery是一个Javascript库,使用其的主要目的是简化J ...
- 线性回归模型(Linear Regression)及Python实现
线性回归模型(Linear Regression)及Python实现 http://www.cnblogs.com/sumai 1.模型 对于一份数据,它有两个变量,分别是Petal.Width和Se ...
- MinGW gcc 生成动态链接库 dll 的一些问题汇总(由浅入深,很详细)
网络上关于用 MinGW gcc 生成动态链接库的文章很多.介绍的方法也都略有不同.这次我在一个项目上刚好需要用到,所以就花了点时间将网上介绍的各种方法都实验了一遍.另外,还根据自己的理解试验了些网上 ...