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> & ...
随机推荐
- QT绘制半透明窗体(改写paintEvent,超级简单)
在派生类中重载QDialog的void paintEvent(QPaintEvent *)事件,在这个函数中加入以下代码 QPainter painter(this); QLinearGradi ...
- lua学习:使用Lua处理游戏数据
在之前lua学习:lua作配置文件里,我们学会了用lua作配置文件. 其实lua在游戏开发中可以作为一个强大的保存.载入游戏数据的工具. 1.载入游戏数据 比如说,现在我有一份表单: data.xls ...
- ALEX WANG(王培沂)品牌_时尚频道_凤凰网
ALEX WANG(王培沂)品牌_时尚频道_凤凰网 ALEX WANG地址: 北京朝阳区百子湾路32号苹果社区10号楼B座2205 订制热线:010-58263402
- linux进程解析--进程切换
为了控制进程的执行,linux内核必须有能力挂起正在cpu上运行的进程,换入想要切换的进程,也就是恢复以前某个挂起的进程,这就是linux的进程切换. 1进程切换的时机 一般来说,进程切换都是发生在 ...
- Android:基于Eclipse编译调试系统级应用源代码
一. 概要描述 在使用Eclipse导入android工程源代码以后,我们可以使用ddms调试和跟踪源代码. 本文讲述动态调试源代码和静态调试源代码的两种方法,避免build system. ...
- java的数据类型,几个java小程序
1:求圆的面积 还好看了c++,不然直接看这课件还真是看不懂……加油吧 要从键盘读入数据可以用Scanner类的nextlnt()或者nextDouble()方法,首先创建Scanner类的一个实例, ...
- java:转换时间格式为String
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); Date curDate = new ...
- shiro权限框架
权限的组成部分:用户 资源 角色 权限 数据库关系表设计是根据自己项目需求设计的 account表role表(id,rolename)account_role(id,aid,rid)permissio ...
- 转:CI引入外部js与css
其实不管是在用CI还是ZF都有同样一个问题,就是路径的问题.前期,我在用ZF做CMS时,我在.htaccess文件中设置了如遇到js,css,img等资源文件都不重定向.但今天在用CI时,却忘记了,搞 ...
- UVA 531 - Compromise(dp + LCS打印路径)
Compromise In a few months the European Currency Union will become a reality. However, to join th ...