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> & ...
随机推荐
- springMVC + mybatis 搜索 分页等
mybatis-3.0.5spring-core-3.2.0.RELEASE等MyBatis3+Spring3当前Spring版本(3.0.5)中未提供对MyBatis3的支持使用第三方jar包进行整 ...
- AseoZdpAseo.init(this, AseoZdpAseo.INSERT_TYPE);
让以后的人知道吧,这就是一个广告包,相当于广告插件.
- gdb图形化调试工具总结
gdb除了命令行方式等的调试之外,还有图形化的调试工具,下面列举一些供参考 1:insight 2: ddd 3: kgdb 4: xxgdb 其它的工具欢迎补充
- JavaScript+XML+VBA导出报表初步构想
最近在做人事档案管理系统遇到的一个问题就是种类多.数量大的报表打印问题.这个系统的一个特点就是信函打印,各种介绍信.各种证明信.对于这样的重复性的功能,最好的方法就是所有的报表实现格式套用. 经过分析 ...
- Eclipse中设置tomcat的启动内存
现象:眼下每次使用Eclipse启动Tomcat 的时候常常出现OutOfMemoryError thrown from the UncaughtExceptionHandler in thread ...
- html 中的块级元素 内联元素
上一个礼拜,做crm项目,使用的大部分都是js,nodejs,ajax 的内容,但是今天我想写写关于html中的块级元素和内联元素 的东西. 首先,html 中的块级元素 内联元素 我们可以看到,这两 ...
- C# 方法的调用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- c语言 ,回调函数[个人理解]
回调函数:把需要调用的方法的指针pCallBackFuncX作为参数传递给一个函数UsrFunction,以便该UsrFunction函数在处理相似事件的时候可以灵活的使用不同的方法. 以在fla ...
- 2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题
听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到10 ...
- django 新闻编辑笔记
url(r'^news_manage/edit/$',views.news_edit,name='edit') url配置 <a href="/management/news_mana ...