这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用KMP解 用0开头的那种类型的 KMP 今天刚好也学了一下,因为KMP的作用是找出最长前缀 KMP 后得到最后一个字符串在前缀当中的最长前缀然后即可以知道在这个最长前缀中可能还有比 最 长 前 缀 更 小 的 子 串 然 后 再 以 这  个 子 串 的 next 从最后开始KMP 然后就可以得到了次子串 这样一直下去

#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
const int maxn = ;
int next[maxn],dp[maxn+],tack[maxn];
char str[maxn];
void getnext(){ int j=;
int Len = strlen(str+);
next[] = next[] = ;
for( int i = ; i <= Len ; i++ )
{
while( j && str[i]!=str[j+] ) j=next[j];
if(str[i]==str[j+]) j++;
next[i] = j;
}
}
int main()
{
while(scanf("%s",str+)==){
fill(dp,dp+maxn,);
getnext();
// int Len= strlen(str);
//for(int i = len-1 ;i < i++ )
int Len = strlen(str+);
for( int i=Len ;i > ; i--)
dp[next[i]]+=dp[i];
int num = ;
int j=next[Len];
while(j){
tack[num++]=j;
j=next[j];
}
printf("%d\n",num+);
for(int i=num-; i >= ; -- i)
printf("%d %d\n",tack[i],dp[tack[i]]);
printf("%d %d\n",Len,);
}
return ;
}

E 这题原来是一个贪心 没想出来 对于每一个位置判断该位置用最小的 然后不断的去扩大他的范围然后 当n+1*n+1 范围内有别的字符存在的时候,或者超出范围 或者 在右上角这个位置可以填写别的字符 时就返回n 否则继续

#include <cstdio>
#include <string.h>
#include <iostream>
using namespace std;
const int maxn = ;
char map[maxn][maxn];
bool in[maxn][maxn];
int N,M;
char tochar(int x,int y){
for( int i='A' ; i <='Z' ; ++i ){
bool falg = true;
if( map[x-][y]==i ) falg = false;
if( map[x][y-]==i )falg =false;
if( map[x][y+]==i ) falg =false;
if( falg ) return i;
}
}
int jud(int x,int y,char &aim){ int num = ;
aim= tochar(x,y);
while(true){
if( x + num > N || y + num > M) return num;
if(in[x][y+num]) return num;
char to=tochar(x,y+num);
if( to != aim) return num;
num++;
}
}
void out(int x,int y,int num ,char t){
for(int i=x; i<x+num; ++i)
for( int j =y ; j< y+num; ++j ){
map[i][j] = t;
in[i][j] =true;
}
}
int main(){ // freopen("out.txt","w",stdout);
memset(in,false,sizeof(in)); memset(map,'a',sizeof(map)); scanf("%d%d",&N,&M); for( int i = ; i <= N ; ++ i)
for( int j = ; j <= M ; ++ j)
if(in[i][j]==false){
char t;
int num= jud(i,j,t);
out(i,j,num,t);
} for( int i= ;i <= N ; ++ i){ for( int j = ;j<=M ; ++ j)
printf("%c",map[i][j]);
printf("\n");
}
return ;
}

Codeforces Round #246 (Div. 2) D E的更多相关文章

  1. Codeforces Round #246 (Div. 2)

    题目链接:Codeforces Round #246 (Div. 2) A:直接找满足的人数,然后整除3就是答案 B:开一个vis数组记录每一个衣服的主场和客场出现次数.然后输出的时候主场数量加上反复 ...

  2. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  3. Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)

    题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策 ...

  4. Codeforces Round #246 (Div. 2) B. Football Kit

    题目的意思是求出每个队穿主场衣服和客场衣服的次数 每个队作为主场的次数是n-1,作为客场的次数是n-1 当每个队打主场的时候肯定穿的主场衣服 当每个队打客场时,如果客场与主场的衣服不同,则穿客场衣服 ...

  5. Codeforces Round #246 (Div. 2) A. Choosing Teams

    给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...

  6. Codeforces Round #246 (Div. 2)——D题

    KMP算法,没写出来,完全不理解NEXT数组.现在理解了很多 答案都在程序中 ,不过这个思想真的很神奇, 还有毛语不好,一直没看懂题目,现在懂了, 大概是:S中前缀等于后缀,求其长度,和其在S中出现了 ...

  7. Codeforces Round #246 (Div. 2) —B. Football Kit

    B. Football Kit time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)

    D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. android 关于view的onTouch和onClick同时触发解决方案

    extends:http://blog.sina.com.cn/s/blog_aa0bd5950101gbwt.html 做了一个悬浮窗,需要处理onTouch和onClick事件, 1 定义一个bo ...

  2. 无约束优化方法(梯度法-牛顿法-BFGS- L-BFGS)

    本文讲解的是无约束优化中几个常见的基于梯度的方法,主要有梯度下降与牛顿方法.BFGS 与 L-BFGS 算法. 梯度下降法是基于目标函数梯度的,算法的收敛速度是线性的,并且当问题是病态时或者问题规模较 ...

  3. iOS SwiftMonkey 随机暴力测试

    参考源文章 https://github.com/zalando/SwiftMonkey https://kemchenj.github.io/2017/03/16/2017-03-16/ 简介 这个 ...

  4. Eigen中的基本函数 及其对应的matlab函数

    原文地址C++矩阵库 Eigen 快速入门 不仅有函数的基本形式,还有对应的matlab函数,用起来很方便. Eigen 矩阵定义 #include <Eigen/Dense> Matri ...

  5. MapReduce规约

    深入了解Combiners编程(相当于Map端的Reduce) 每一个map可能会产生大量的输出,combiner的作用就是在map端对输出先做一次合并,以减少传输到reducer的数据量. comb ...

  6. ZOJ 3983 - Crusaders Quest - [DFS]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3983 题意: 给出一个长度为 $9$ 的字符串 $s$,且 $s ...

  7. win7操作系统说明

    · 能够使用windows7操作系统成为了许多电脑用户的一大喜悦之事,相比之前的Vista系统,windows7系统真的是好看了,快了,好用了,但你是否担心自己的windows7系统就像新安装其他Wi ...

  8. FMOD变声如何捕获并存储处理音效之后的数据

    类似AVAudioEngine的功能,一个Engine可以将N个connect连接(串联和并联)在一起,这样来实现多个输入源,多层处理效果的混合输出.实现这个所需功能也是通过这样的方案来实现的.也就是 ...

  9. 堆内存泄漏移除导致tcp链接异常高

    故障现象: 1:活动前端Nginx服务器TCP连接数到1万多 2:活动后端Tomcat其中1台TCP连接数达4千,并且CPU瞬间到780%(配置8核16G),内存正常 3:重启后端Tomcat后,TC ...

  10. idea 创建的maven+spring+mybatis项目整合 报错无法创建bean

    报错如下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with n ...