这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用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. centos6上使用xfs文件系统

    ext4目前也还没有真的支持16TB以上的单分区空间,由于工具的限制,只能创建最大为16T的单分区决定直接用xfs 安装xfs [root@ ~]$ yum install kmod-xfs xfsp ...

  2. Gnome排序

    Gnome排序(地精排序),起初由Hamid Sarbazi-Azad 于2000年提出,并被称为stupid排序,后来被Dick Grune描述并命名为“地精排序”,作为一个排序算法,和插入排序类似 ...

  3. 23种设计模式之代理模式(Proxy)

    代理模式是一种对象结构型模式,可为某个对象提供一个代理,并由代理对象控制对原对象的引用.代理模式能够协调调用者和被调用者,能够在一定程度上降低系统的耦合度,其缺点是请求的处理速度会变慢,并且实现代理模 ...

  4. 【CF887E】Little Brother 二分+几何

    [CF887E]Little Brother 题意:给你n个圆和一条线段,保证圆和圆.圆和线段所在直线不相交,不相切,不包含.求一个过线段两端点的圆,满足不和任何圆相交(可以相切.包含).问圆的最小半 ...

  5. imageView 的contentMode问题

    UIViewContentModeScaleToFill : 图片拉伸至填充整个UIImageView(图片可能会变形) UIViewContentModeScaleAspectFit : 按照原来的 ...

  6. Twig---和vue或angular前端框架并存

    <h1> {% verbatim %} {{message}} {% endverbatim %} </h1> 上面这种方式虽然能够解决,前台渲染的问题,但是还是会报错: 第二 ...

  7. postgresql----文本搜索类型和检索函数

    postgresql提供两种数据类型用于支持全文检索:tsvector类型产生一个文档(以优化全文检索形式)和tsquery类型用于查询检索. tsvector的值是一个无重复的lexemes排序列表 ...

  8. POJ-1887 Testing the CATCHER(dp,最长下降子序列)

    Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...

  9. POJ 2406 - Power Strings - [KMP求最小循环节]

    题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...

  10. Kettle 4.2源码分析第一讲--Kettle 简介

    Pentaho Data Integration(PDI)简介 1. PDI结构简介 图 1‑1 PDI核心组件 Spoon是构建ETL Jobs和Transformations的工具.Spoon可以 ...