当前位置:网站首页>[NK] question de calcul de 51 g pour le match lunaire Bullock
[NK] question de calcul de 51 g pour le match lunaire Bullock
2022-06-10 21:46:00 【* DDL Gzmblog】
Préface
t a g : tag : tag:StringUne chaîne de palindromeshashDeux pointsDifficile.
Porte de transfert :
Titre :
Vous avez une longueur de n n nLa chaîne de,Vous pouvez choisir de supprimer un suffixe(Peut être vide),Puis modifiez un des caractères de la chaîne restante,Pour en faire une chaîne de palindromes.Combien de chaînes de palindromes possibles peuvent être générées à la fin.
Il faut s'assurer que les jeux de caractères ne contiennent que des lettres minuscules tout au long du processus.Où l'opération de modification doit être modifiée,Mais les caractères peuvent être changés en caractères originaux.
Idées :
Nous pouvons diviser les chaînes restantes en trois catégories
C'est un palindrome,Il manque deux palindromes,Beaucoup de palindromes
Pour ceux qui sont eux - mêmes des palindromes
Si c'est une longueur impaire qui contribue + 26 +26 +26,Sinon, contribuer + 1 +1 +1
Pour un palindrome
Parce qu'il ne doit pas y avoir de non - palindrome entre les nombres impairs,Donc impair==Cas pair.Écrivez quelques contributions pour savoir + 2 +2 +2
Ce qui suit est de déterminer si un palindrome
Apparemment, on peut d'abord calculer Tableau de hachage
Quand le positif et le négatif HashiL'égalité est un palindrome
Comment juger un palindrome
On peut passer par ici. Deux points
Prenez le point médian comme point de départ,Et ensuite, la moitié de la longueur
Quand m i d − l e n , m i d + l e n mid-len,mid+len mid−len,mid+lenIl est temps que,Apparemment non.,Continuez sur les deux points
Donc monotone
Super dur à écrire.
code :
// Problem: Question de calcul
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11228/G
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false);
#define CIT cin.tie(0);
#define COT cout.tie(0);
#define ll long long
#define ull long long
#define x first
#define y second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),x.end()
#define Fup(i,a,b) for(int i=a;i<=b;i++)
#define Fde(i,a,b) for(int i=a;i>=b;i--)
#define cer(a) cerr<<#a<<'='<<(a)<<" @ line "<<__LINE__<<" "<<endl
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<int,int> mp;
const int N = 2e5+10,INF = 0x3f3f3f3f , P = 13;
const double eps = 1e-5;
ull h[N],p[N],rh[N];
char str[N];
int n;
ull get(int l,int r){
return h[r] - h[l-1]*p[r-l+1];
}
ull rget(int l,int r){
return rh[r] - rh[l-1]*p[l-1];
}
void calc(){
p[0] = 1;
for(int i=1;i<=n;i++){
h[i] = h[i-1]*P + str[i];
rh[n-i+1] = rh[n-i+2]*P+str[n-i+1];
p[i] = p[i-1]*P;
}
}
int search(int st1,int st2,int len){
int l = 1 ,r = len;
int ans = 0 ;
while(l<=r){
int mid = (l+r)>>1;
// if(get(st1+1,st1+mid) == rget(st2+1,st2 - mid)) l = mid+1;
// else ans = mid, r = mid-1;
if(h[st1+mid] - h[st1]*p[mid] == rh[st2-mid] - rh[st2]*p[mid]) l = mid+1;
else ans = mid , r = mid-1;
}
return st1+ans;
}
void solve(){
cin>>n;
cin>>(str+1);
calc();
ll ans = 0 ;
int x = 0, y = 0 ;
for(int i=1;i<=n;i++){
// if(get(1,i) == rget(i+2,1)){
if(h[i] - h[0]*p[i] == rh[1] - rh[i+1]*p[i]){
if(i&1) ans +=26;
else ans++;
continue;
}
x = search(0,i+1,i);
y = search(x,i+1-x,i-x);
if(y == search(y,i+1-y,i-y))ans+=2;
}
cout<<ans<<endl;
}
int main(){
//int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- What should be paid attention to when designing Multilayer PCB?
- Interview Essentials - basic knowledge of synchronized underlying principles
- ThinkPHP v6.0.x反序列化漏洞复现
- C language -- 8 familiar keywords
- Read the source code of micropyton - add the C extension class module (1)
- 编程式导航路由跳转到当前路由(参数不变), 多次执行会抛出NavigationDuplicated的警告错误?
- CentOS7环境下MySQL8常用命令小结
- Attack and defense drill | network security "whistleblower": security monitoring
- 实用 | 如何利用 Burp Suite 进行密码爆破!
- shell实现ssh登录并执行命令
猜你喜欢

你的公司会选择开发数据中台吗?

用少儿编程思维塑造青少年领悟能力

Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test

北大青鸟昌平校区:高中学历可以学UI吗?

Attack and defense drill | network security "whistleblower": security monitoring

C language -- 8 familiar keywords

Course design of imitation pottery ticket of wechat applet

解读创客空间下的教育新生态

详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)

Use DAP link to download the executable file separately to the mm32f5 microcontroller
随机推荐
What do software test engineers do?
自制Table錶格
旋转菜单2.0
C language learning review -- 1 basic knowledge review
自制Table表格
CCF class a conference or journal - regression related papers
蛮力法/任务分配
Self made table
Factory and strategy mode implementation scheme of coupons
Cas de test app
Notes to entry: do I need to know programming for O & M?
Nanny tutorial: how to become a contributor to Apache linkis documents
Rotate menu 3.0
Fast Planner - detailed explanation of kinetic astar
C language ---9 first knowledge of macros and pointers
2021年平均工资出炉,IT行业不出所料
Leetcode advanced path - Search insertion location
自媒体视频创作如何选择领域?
C language -- 10 first knowledge of structure
H265 Nalu type judgment and SPS data analysis