这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用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. Mavlink - 无人机通讯协议

    http://qgroundcontrol.org/mavlink/start mavlink协议介绍https://pixhawk.ethz.ch/mavlink/ 消息简介 MAVLink简介 M ...

  2. MySQLCouldn't find MySQL manager

    mysql出现MySQLCouldn't find MySQL manager错误的解决办法 最近我的一个linux服务器上的网站全部无法打开.....访问网站没有提示.....只出现该页无法显示的错 ...

  3. 如何将Win10 的环境变量页面设置用在win7上面?

    如何将Win10 的环境变量设置用在win7上面? Win7一般是如下设置: Win10 是如下设置: 解决办法: 注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentContr ...

  4. 【转】JavaScript prototype

    原文地址:http://www.cnblogs.com/dolphinX/p/3286177.html 用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初 ...

  5. HDU 3480 - Division - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3480 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  6. 基于元胞自动机NaSch模型的多车道手动-自动混合驾驶仿真模型的Matlab实现

    模型的建立基本来自于:http://www.doc88.com/p-2078634086043.html 花了一天半的时间用新学会的matlab实现了一下. ───────────────────── ...

  7. 【源码】rm zip 删除文件夹中大量的小文件 百万 扫描文件时间

    rm  删除文件夹中大量的小文件 百万 迟迟未删除 在扫描文件? rm删除命令源码分析 - ty_laurel的博客 - CSDN博客 https://blog.csdn.net/ty_laurel/ ...

  8. 《Nginx - location配置》

    一:Location 作用 - location 定位 ,也就是可以通过不同URL进行定位,可以很大的增加它配置的灵活性. 二:相关变量 示例: http://192.168.27.27/xxxx $ ...

  9. The Unique MST----poj1679次小生成树

    题目链接:http://poj.org/problem?id=1679 判断最小生成数是否唯一:如果唯一这权值和次小生成树不同,否则相同: #include<stdio.h> #inclu ...

  10. sed与grep正则

     string editor  流编辑器 sed编辑器是一行一行的处理内容,正在处理的内容存放在缓冲区内,处理完后 按照选项的规定进行输出或者修改文件 option: -n 静默模式结合p可以只输出修 ...