这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用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. State Server实现多机器多站点 Session 共享 全手记

    网络环境有2台windows 2008 (192.168.1.71,192.168.1.72) 需要部署成 WebFarm,提高容错性. 网站部署在2台机器上的2个站点,如何才能做到Session的共 ...

  2. 基础笔记1(进制,浮点,递归,floor,round和ceil)

    1,进制默认是十进制 0开头 8进制 0x     16进制 0b     2进制 2,long 的范围是19位数字.int范围是21亿左右,short 是三万二千左右. 超过int范围的long类型 ...

  3. Google Drive 里的文件下载的方法

    Google Drive 里并不提供创建直接下载链接的选项,但是可以通过小小的更改链接形式就能把分享的内容保存到本地.例如,一份通过 Google Drive 分享的文件链接形式为: https:// ...

  4. 搭建linux远程服务器和传输下载文件

    其实,将ubuntu系统设置为服务器很简单,只需要开启ssh服务就可以了.开启了ssh服务以后,其它电脑就可以通过ssh登录你的这台ubuntu服务器.SSH分客户端openssh-client和op ...

  5. ubuntu16.04配置tensorflow-gpu环境

    1.安装驱动 参考: 史上最全的ubuntu16.04安装nvidia驱动+cuda9.0+cuDnn7.0 https://blog.csdn.net/qq_31215157/article/det ...

  6. Oracle体系结构之数据文件管理

    数据文件分2个方向管理: 物理结构和逻辑结构. 数据库的存储层次结构图: ............. 逻辑结构:                                  物理结构: .... ...

  7. 21.5.3 Updatable and Insertable Views

    http://dev.mysql.com/doc/refman/5.7/en/view-updatability.html Some views are updatable and reference ...

  8. iOS-动画之CoreAnimation框架(转载)

    一.简介 iOS动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide.Core Animation是iOS和macOS平台上负责图形渲染与动画的基 ...

  9. 多线程情况下HashMap死循环的问题

    1.多线程put操作后,get操作导致死循环. 2.多线程put非null元素后,get操作得到null值. 3.多线程put操作,导致元素丢失. 死循环场景重现 下面我用一段简单的DEMO模拟Has ...

  10. pandas2

    1.Series创建的方法统一为pd.Series(data,index=)(1,2,3)Series可以通过三种形式创建:python的dict.numpy当中的ndarray(numpy中的基本数 ...