【2017中国大学生程序设计竞赛 - 网络选拔赛】A Secret
【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6153
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); const int N=1e6;
const LL MOD = 1e9+7;
int Next[N+10],extend[N+10],lent,lens;
char S[N+10],T[N+10]; void makenext(int m){
int a = 0;
Next[0] = lens;
while(a < lens - 1 && S[a] == S[a + 1]) a++;
Next[1] = a;
a = 1; for(int k = 2; k < lens; k ++) {
int p = a + Next[a] - 1,L = Next[k - a];
if( (k - 1) + L >= p) {
int j = (p - k + 1) > 0 ? (p - k + 1) : 0;
while(k + j < lens && S[k + j] == S[j]) j++;
Next[k] = j;
a = k;
} else
Next[k] = L;
}
}
void GetNext(const char *T){
int a=0;
int MinLen = lens < lent ? lens : lent;
while(a < MinLen && S[a] == T[a] ) a++;
extend[0]=a;
a=0;
for(int k=1;k < lent;k++){
int p=a+extend[a]-1,L = Next[k-a];
if((k-1)+L>=p){
int j=(p-k+1)>0? (p-k+1):0;
while(k + j < lent && T[k+j] == S[j]) j++;
extend[k]=j;
a=k;
}
else extend[k]=L;
}
} int main(){
//Open();
int TT;
ri(TT);
while (TT--){
rs(T),rs(S);
lent = strlen(T),lens = strlen(S);
reverse(T,T+lent),reverse(S,S+lens);
makenext(lens);
GetNext(T);
LL sum = 0;
rep1(i,0,lent-1){
//extend[i] = min(extend[i],lens);
// 1 + 2 + .. extend[i]
sum = (sum + 1LL*(1 + extend[i])*extend[i]/2)%MOD;
}
ol(sum);puts("");
}
return 0;
}
【2017中国大学生程序设计竞赛 - 网络选拔赛】A Secret的更多相关文章
- HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1004 HDU 6153 A Secret (字符串处理 KMP)
题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a presen ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)
题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appe ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1003 HDU 6152 Friend-Graph (模拟)
题目链接 Problem Description It is well known that small groups are not conducive of the development of ...
随机推荐
- Linux打包免安装的Qt程序(编写导出依赖包的脚本copylib.sh,程序启动脚本MyApp.sh)
本文介绍如何打包Qt程序,使其在没有安装Qt的系统可以运行. 默认前提:另外一个系统和本系统是同一个系统版本. 1,编写导出依赖包的脚本copylib.sh #!/bin/bash LibDir=$P ...
- css footer not displaying at the bottom of the page
https://stackoverflow.com/questions/15960290/css-footer-not-displaying-at-the-bottom-of-the-page The ...
- spring-cloud导入eclipse时,@slf4j注解为什么找不到log变量
原因是缺少插件Lomboz. Lomboz是一个基于LGPL的开源J2EE综合开发环境的Eclipse插件,对编码,发布,测试,以及debug等各个软件开发的生命周期提供支持,支持JSP,EJB等.L ...
- css3 背景过度实现
代码: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&q ...
- Tensorlfow学习笔记----collection
本文来源:http://blog.csdn.net/u012436149/article/details/53894354 tensorflow 之 collection tensorflow的c ...
- ls---显示文件目录各项信息
ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 ls(选项)(参数) 选项 -a:显示所有档案及目录(ls内定将档案名 ...
- 【Uva 1601】The Morning after Halloween
[Link]: [Description] 给你一张平面图; 最多可能有3只鬼; 给出这几只鬼的初始位置; 然后,这几只鬼有各自的终点; 每秒钟,这几只鬼能同时移动到相邻的4个格子中的一个 任意两只鬼 ...
- 安装Apache PHP MySQL PHPMyAdmin
视频教程:https://www.youtube.com/watch?v=FJC2iGt_2bc,Youtube看不了的FQ吧-3- 本人参考这篇文章:http://blog.csdn.net/kno ...
- qt qlineedit只输入数字
lineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
- 具体解释NoSQL数据库使用实例
一.NoSQL基础知识 1.关于NoSQL 在"NoSQL"一词.实际上是一个叫Racker的同事创造的,当约翰埃文斯埃里克要组织一次活动来讨论开源的分布式数据库. 这个名称和概念 ...