Codeforces Round #246 (Div. 2) D E
这题说的是给了一个字符串当前缀和后缀相同的时候就计算此时的 整个串种拥有这样的子串友多少个,没想到用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的更多相关文章
- Codeforces Round #246 (Div. 2)
题目链接:Codeforces Round #246 (Div. 2) A:直接找满足的人数,然后整除3就是答案 B:开一个vis数组记录每一个衣服的主场和客场出现次数.然后输出的时候主场数量加上反复 ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)
题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策 ...
- Codeforces Round #246 (Div. 2) B. Football Kit
题目的意思是求出每个队穿主场衣服和客场衣服的次数 每个队作为主场的次数是n-1,作为客场的次数是n-1 当每个队打主场的时候肯定穿的主场衣服 当每个队打客场时,如果客场与主场的衣服不同,则穿客场衣服 ...
- Codeforces Round #246 (Div. 2) A. Choosing Teams
给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...
- Codeforces Round #246 (Div. 2)——D题
KMP算法,没写出来,完全不理解NEXT数组.现在理解了很多 答案都在程序中 ,不过这个思想真的很神奇, 还有毛语不好,一直没看懂题目,现在懂了, 大概是:S中前缀等于后缀,求其长度,和其在S中出现了 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- [Log]ASP.NET之HttpModule 事件执行顺序
ASP.Net下的HttpModule是基于事件的处理模型,这使得我们在选择事件监听和处理的时候有更多选择.下面是对HttpModule有关事件被触发的监测: 有关代码如下 using System; ...
- CentOS安装php及其扩展
列出所有的可安装的软件包 yum list | grep php56w* | grep redis 安装php及其扩展 yum install -y php56w php56w-mysql php5 ...
- PHP将富文本内容去除各类样式图片等只保留txt文本内容(作用于SEO的description)
1.从数据库读取富文本内容样式如下: <p style=";text-indent: 0;padding: 0;line-height: 26px"><span ...
- vue--获取监听获取radius的改变
做一个考试系统,单选题都是后台来的数据,所以一时间没有想到 @change这个方法: <template> <div id="Home"> <v-he ...
- 1.8TF的分类
TF识别手写体识别分类 #-*- coding: utf-8 -*- # @Time : 2017/12/26 15:42 # @Author : Z # @Email : S # @File : 1 ...
- php:// — 访问各个输入/输出流(I/O streams)
PHP: php:// - Manual http://www.php.net/manual/zh/wrappers.php.php php:// php:// — 访问各个输入/输出流(I/O st ...
- inaccessible
$w = (object)array('key0'=>'a','key1'=>'b',0,1,2,0=>'0w',1=>'1w','11'=>'11str'); var_ ...
- RFQ 、IFB、RFP 、RFI的区别是什么
询价类型 信息索取书 RFI 报价申请书 RFQ 建议要求书 RFP 投标邀请书 IFB 目的 获得与产品服务供应商相关信息 取得供应商对所需产品.服务或服务的承诺 要求供应商对需求提出最好解决方案建 ...
- 我读过的最好的epoll讲解(转)
原文:http://zhihu.com/question/20122137/answer/14049112 作者:蓝形参来源:知乎 首先我们来定义流的概念,一个流可以是文件,socket,pipe等等 ...
- ChinaTest测试感悟
这次去北京参加ChinaTest大会,听了各位大师和同行的心得和感悟,收获颇多.很喜欢这样的大会,可以听到测试的各种声音各种观点.当没有对错时,需要思考的就是怎样采取最适合当前环境的策略.言归正传,谈 ...