Codeforces Round #401 (Div. 2) D. Cloud of Hashtags【模拟、贪心】
来源:互联网 发布:阿里云邮箱app 编辑:程序博客网 时间:2024/06/09 22:35
D. Cloud of Hashtags
题意:
1.给你 #
开头。
2.让你删除掉最少的一些字符,从而形成
思路:
1.贪心策略:从后往前推,即是形成字典序不递增的字符串,这样可以使得保留最多,即删除最少。
2.每次计算,只与后一列有关系。
3.直接比对模拟取子串就行了。
代码:
#include <bits/stdc++.h>using namespace std;char s[500500];string buf[500500];char minn[500500];string scf() { scanf("%s", &s); return s;}int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) buf[i] = scf(); for(int i = 0; i < buf[n-1].size(); i++) minn[i] = buf[n-1][i]; int idx = buf[n-1].size(); for(int i = n-2; i >= 0; i--) { string tp = buf[i]; tp = tp.substr(0, idx); int to = min(idx, (int)tp.size()); for(int j = 0; j < to; j++) { if(tp[j] < minn[j]) { minn[j] = tp[j]; tp = buf[i]; for(int k = j; k < tp.size(); k++) minn[k] = tp[k]; break; } else if(tp[j] > minn[j]) { tp = tp.substr(0, j); break; } } idx = tp.size(); buf[i] = tp; } for(int i = 0; i < n; i++) cout << buf[i] << endl;}
阅读全文
0 0
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags【模拟、贪心】
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2)D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags 贪心、字符串处理
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(暴力)
- Codeforces Round #401(Div. 2)D. Cloud of Hashtags【逆序思维】
- Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 串
- (codeforces)D. Cloud of Hashtags
- 【CodeForces 777D】Cloud of Hashtags (模拟+字符串处理)
- 【codeforces 777D】Cloud of Hashtags
- Codeforces 777D-Cloud of Hashtags
- 【Codeforces 777 D Cloud of Hashtags】
- CodeForces 777D Cloud of Hashtags
- D. Cloud of Hashtags
- codeforces 777D. Cloud of Hashtags (逆序思维)
- 777D. Cloud of Hashtags
- 【贪心】Codeforces Round #339 (Div. 2) D
- 表达式求值
- HDOJ 基础动归汇总 ,持续更新题目,一路打怪升级
- IDEA中Maven报错NoClassDefFoundError
- 《大话数据结构》学习笔记--chapter 6
- 关于Spring MVC中的表单标签库的使用
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags【模拟、贪心】
- hibernate_2
- 8.10-8.11训练总结
- BZOJ 4756 Promotion Counting(线段树合并 || dfs)
- 给自己一次警告——NSNotification
- Camtasia 9全套视频入门到精通
- 图论--网络流初步(最大流,增广路)
- 如何用svn新建属于自己的分支
- mysql 常用命令技巧大全