CF 319D(Have You Ever Heard About the Word?-模拟)
6 seconds
256 megabytes
standard input
standard output
A substring of a string is a contiguous subsequence of that string. So, string bca is substring of string abcabc, but string cc is not.
A repeating block is a string formed by concatenating some string with itself. So, string abcabc is a repeating block, but strings abcabd,ababab are not.
You've got a sequence of Latin characters (string). At each step you find the shortest substring that is a repeating block, if there exists more than one you must choose the leftmost. As the substring is of form XX (X — some string) you replace this substring with X, in other words you delete one of the X substrings in the substring. You repeat this process until there remains no repeating block in the string.
How would the final string looks like? Look at the sample explanation to understand the statement more precise.
In the first line of input you're given a string of small Latin characters with length between 1 to 50000, inclusive.
Print the final string after applying changes.
abccabc
abc
aaaabaaab
ab
birdbirdbirdistheword
birdistheword
At the first sample the string transforms as follows: abccabc → abcabc → abc.
At the second sample the string transforms as follows: aaaabaaab → aaabaaab → aabaaab → abaaab → abaab → abab → ab.
模拟能过……
E文是硬伤,要的是最短中最左子串,不是最左中最短子串……
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<cctype>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define RepD(i,n) for(int i=n;i>=0;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define MEMI(a) memset(a,127,sizeof(a))
#define MEMi(a) memset(a,128,sizeof(a))
#define MAXN (50000+10)
char s[MAXN];
int main()
{
// freopen("CF319D.in","r",stdin);
// freopen(".out","w",stdout);
int t=1;
while (t--)
{
int n=strlen(gets(s+1));
For(len,n/2)
{
int tot=0;
For(j,n-len)
{
if (s[j]==s[j+len]) tot++;else tot=0;
if (tot==len)
{
Fork(k,j+1,n-len) s[k]=s[k+len];
n-=len;len=0;break;
}
}
}
s[n+1]=0;
puts(s+1);
}
return 0;
}
CF 319D(Have You Ever Heard About the Word?-模拟)的更多相关文章
- Codeforces 319D Have You Ever Heard About the Word?
首先会想到|x|是不递减的. 于是可以枚举长度L. 再每个L设一个断点,xx必定经过两个断点. 两两断点间求最长公共前后缀,这里用hash+二分会快. 然后一波扫过去就好了. 如果找到了,hash就要 ...
- Codeforce 水题报告
最近做了好多CF的题的说,很多cf的题都很有启发性觉得很有必要总结一下,再加上上次写题解因为太简单被老师骂了,所以这次决定总结一下,也发表一下停课一星期的感想= = Codeforces 261E M ...
- SDUT 2351 In Danger
点我看题目 题意 : 有n个兵想要自杀,所以他们决定围成一个圈,从1开始一直环到n,然后每第2个开始自杀,但是有一个兵不想死,所以让你编程求出最后一个应该死的人的位置,这样的话就剩他自己他可以不自杀了 ...
- hbase--知识点总结2
--用java操作hbase 1.配置jar包环境 创建hbase项目 --> 新建folder文件夹 --> 将hbase相关jar包全部导入到java项目之中 --> add b ...
- 32位和64位系统内核函数调用从ZwProtectVirtualMemory到NtProtectVirtualMemory
0x01 前言 我们知道R3层中,Zw系列函数和Nt系列函数函数是一样的,但是在内核Zw系列函数调用了Nt系列函数,但是为什么要在内核设置一个Zw系列函数而不是直接调用Nt函数呢?Zw系列函数又是怎么 ...
- 目标&计划
目标 感觉起来NOIP还是能考到一个比较好的分数的吧 550+? 现在可能还不大行,但是过3个月或许还是能考到的 所以先订下NOIP保底500争取550+吧 至于省选... 前面有一群巨佬挡着,感觉想 ...
- Codeforces Round #189 (Div. 1 + Div. 2)
A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二 ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- storm-redis 详解
多的不说,先来代码分析,再贴我自己写的代码.如果代码有错误,求更正.. 导入两个关键包,其他项目需要的包,大家自己导入了,我pom下的包太多,不好一下扔上来. <dependency> & ...
随机推荐
- 7,C++ public, protected, private 继承的区别
在某处看到一张图,简单明了的说明了三者的关系,很是佩服,遂记录下来. //公有继承 对象访问 成员访问 public --> public Y Y protected --> protec ...
- Objective-C基础教程读书笔记(7)
第7章 深入了解Xcode Xcode是一个很好用的工具,有很多强大的功能,不过并不是所有的功能都易于发现.如果你打算长期使用这个强大的工具,就肯定要尽可能多了解它.本章将介绍一些Xcode编辑器的使 ...
- android代码实现关机
1.API没有开放,需要提升为syetem app级别! 2.android 模块编译,mm 命令 2.1.先进入顶层 source build/envsetup.sh 2.2.进入目录 m ...
- [转]Java Code Examples for android.util.JsonReader
[转]Java Code Examples for android.util.JsonReader The following are top voted examples for showing h ...
- B站开源播放框架ijkplayer(iOS版)使用教程
最近在关注直播这块儿,开始时直接用ffmpeg写了一个,写得比较烂,卡顿很严重,后来听说了B站开源播放框架ijkplayer,于是就去试试看这是链接 ,一用之下果然不错,逢人便向人安利,可总是有部分同 ...
- 在VS上配置OpenCV
这几篇帖子讲的挺仔细的,而且不坑,结合看看就没问题了~~ http://www.cnblogs.com/cuteshongshong/p/4057193.html http://my.phirobot ...
- 【集训笔记】归纳与递推【HDOJ1297
例:(2050)折线分割平面 问题描述: 平面上有n条折线,问这些折线最多能将平面分割成多少块? 样例输入 1 2 样例输出 2 7 平面上有n条折线,问这些折线最多能将平面分割成多少块? 解: 折线 ...
- TensorFlow文本与序列的深度模型
TensorFlow深度学习笔记 文本与序列的深度模型 Deep Models for Text and Sequence 转载请注明作者:梦里风林Github工程地址:https://github. ...
- Java, C#, Swift语法对比速查表
原文:Java, C#, Swift语法对比速查表 Java 8 C# 6 Swift 变量 类型 变量名; 类型 变量名; var 变量名 : 类型; 变量(类型推断) N/A var 变量名= ...
- Android Studio apk 打包流程
1.Build -> Generate Signed APK...,打开如下窗口 2.假设这里没有打过apk包,点击Create new,窗口如下 这里只要输入几个必要项 Key store p ...