日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

是男人就过 8 题--Pony.AI 题 - A String Game

發(fā)布時(shí)間:2023/12/3 ChatGpt 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 是男人就过 8 题--Pony.AI 题 - A String Game 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

是男人就過 8 題--Pony.AI 題 - A String Game


題目來源

題意:給一個(gè)串t以及n個(gè)t的子串s,兩個(gè)人每輪可以選擇一個(gè)s在他的后邊添加一個(gè)字符滿足得到的新串仍是t的子串,第一個(gè)不能操作的人輸。

做法:對(duì)s串建SAM,在一個(gè)子串后邊添加字符,等價(jià)于在SAM上向后移動(dòng)一步,預(yù)處理每個(gè)狀態(tài)的sg函數(shù),將n個(gè)子串的答案異或起來。SAM空間要開兩倍(女裝警告~~

#include <bits/stdc++.h> #define pb push_back #define rep(i,a,b) for(int i=a;i<=b;++i) const int N = 2e5 + 7; typedef long long ll; using namespace std;struct SAM {int n, step[N], fa[N], num[N], last, root, cnt;char s[N];map<char , int> ch[N];void init() {for(int i = 0; i <= cnt; ++i) ch[i].clear();cnt = 0; last = root = ++cnt;}void add(int x) {int tmp = s[x], p = last, np = ++cnt;step[last = np] = x;while(p && !ch[p][tmp]) ch[p][tmp] = np, p =fa[p];if(!p) fa[np] = root;else {int q = ch[p][tmp];if(step[q] == step[p] + 1) fa[np] = q;else {int nq = ++ cnt; step[nq] = step[p] + 1;ch[nq] = ch[q];fa[nq] = fa[q], fa[q] = fa[np] = nq;while(ch[p][tmp] == q) ch[p][tmp] = nq, p = fa[p];}}}int A[N], sg[N], vis[N];void init_sg() {memset(A, 0 , sizeof(A));memset(sg, 0 , sizeof(sg));memset(vis, 0 , sizeof(vis));for(int i = 1; i <= cnt; ++i) ++ A[step[i]];for(int i = 1; i <= n; ++i) A[i] += A[i-1];for(int i = cnt; i; --i) num[A[step[i]]--] = i;for(int i = cnt; i; --i) {for(auto x: ch[num[i]]) {int t = x.second;vis[sg[t]] = num[i];}for(int j = 0; ; ++j) if(vis[j] != num[i]) {sg[num[i]] = j; break;}}}int cal_sg(char str[]) {int len = strlen(str+1), now = root;for(int i = 1; i <= len; ++i) now = ch[now][str[i]];return sg[now];}void run() {init();for(int i = 1; i <= n; ++i) add(i);init_sg();} } Fe; char str[N]; int main() {while(scanf(" %s",Fe.s+1) != EOF) {Fe.n = strlen(Fe.s+1);Fe.run(); int n;scanf("%d",&n);int ans = 0;rep(i, 1, n) {scanf(" %s",str+1);ans ^= Fe.cal_sg(str);}puts(ans ? "Alice" : "Bob");}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/RRRR-wys/p/10184137.html

總結(jié)

以上是生活随笔為你收集整理的是男人就过 8 题--Pony.AI 题 - A String Game的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。