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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

P3121 [USACO15FEB]审查(黄金)Censoring (Gold)

發(fā)布時間:2025/3/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P3121 [USACO15FEB]审查(黄金)Censoring (Gold) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his cows not see (clearly, the magazine is in need of better editorial oversight).

FJ has taken all of the text from the magazine to create the string S of length at most 10^5 characters. He has a list of censored words t_1 ... t_N that he wishes to delete from S. To do so Farmer John finds the earliest occurrence of a censored word in S (having the earliest start index) and removes that instance of the word from S. He then repeats the process again, deleting the earliest occurrence of a censored word from S, repeating until there are no more occurrences of censored words in S. Note that the deletion of one censored word might create a new occurrence of a censored word that didn't exist before.

Farmer John notes that the censored words have the property that no censored word appears as a substring of another censored word. In particular this means the censored word with earliest index in S is uniquely defined.

Please help FJ determine the final contents of S after censoring is complete.

FJ把雜志上所有的文章摘抄了下來并把它變成了一個長度不超過10^5的字符串S。他有一個包含n個單詞的列表,列表里的n個單詞記為t_1...t_N。他希望從S中刪除這些單詞。

FJ每次在S中找到最早出現(xiàn)的列表中的單詞(最早出現(xiàn)指該單詞的開始位置最小),然后從S中刪除這個單詞。他重復(fù)這個操作直到S中沒有列表里的單詞為止。注意刪除一個單詞后可能會導(dǎo)致S中出現(xiàn)另一個列表中的單詞

FJ注意到列表中的單詞不會出現(xiàn)一個單詞是另一個單詞子串的情況,這意味著每個列表中的單詞在S中出現(xiàn)的開始位置是互不相同的

請幫助FJ完成這些操作并輸出最后的S

輸入輸出格式

輸入格式:

The first line will contain S.

The second line will contain N, the number of censored words. The next N lines contain the strings t_1 ... t_N. Each string will contain lower-case alphabet characters (in the range a..z), and the combined lengths of all these strings will be at most 10^5.

輸出格式:

The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process.

輸入輸出樣例

輸入樣例#1:? begintheescapexecutionatthebreakofdawn 2 escape execution 輸出樣例#1:? beginthatthebreakofdawn

?

Solution:

  Water!本題和前面那題思路完全一樣,只不過變成了多模式串,只需將模式串建好AC自動機,每次用棧記錄失配邊所指向的節(jié)點,然后若匹配到了一個模式串就回到當前節(jié)點深度之前的棧中的節(jié)點,繼續(xù)匹配就好了。

代碼:

?

#include<bits/stdc++.h> #define il inline #define ll long long #define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--) using namespace std; const int N=1e5+7; int trie[N][26],cnt,fail[N],lst[N],ed[N],n,dep[N],stk[N],tot; char s[N],t[N],ans[N];il void insert(char *s){int len=strlen(s),p=0,x;For(i,0,len-1){x=s[i]-'a';if(!trie[p][x])trie[p][x]=++cnt,dep[cnt]=dep[p]+1;p=trie[p][x];}ed[p]++; }il void bfs(){queue<int>q;For(i,0,25) if(trie[0][i]) q.push(trie[0][i]),fail[trie[0][i]]=0;while(!q.empty()){int u=q.front();q.pop();For(i,0,25){int &v=trie[u][i];if(v) fail[v]=trie[fail[u]][i],lst[v]=ed[fail[v]]?fail[v]:lst[fail[v]],q.push(v);else v=trie[fail[u]][i];}} }il void solve(char *s){int len=strlen(s),p=0;For(i,0,len-1){ans[++tot]=s[i];p=trie[p][s[i]-'a'];for(int j=p;j;j=lst[j]) if(ed[j]){tot-=dep[j];p=stk[tot];break;}stk[tot]=p;}For(i,1,tot) printf("%c",ans[i]); }il void init(){scanf("%s%d",t,&n);For(i,1,n)scanf("%s",s),insert(s);bfs();solve(t); }int main(){init();return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/five20/p/9473449.html

總結(jié)

以上是生活随笔為你收集整理的P3121 [USACO15FEB]审查(黄金)Censoring (Gold)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 92精品 | 日韩欧美国产综合 | 波多野结衣在线视频免费观看 | 伊人成综合网 | 久久艹影院| 性色在线观看 | 欧美 日本 国产 | 求一个黄色网址 | 亚洲第一视频在线观看 | 免费v片在线观看 | 五月天精品视频 | 狠狠躁18三区二区一区视频 | 欧美抠逼视频 | 91黄色大片 | 日韩精品在线观看一区 | 午夜电影网站 | 国产喷水在线 | www.色在线| 成人人伦一区二区三区 | 亚洲专区视频 | 色香蕉网站 | 乳揉みま痴汉4在线播放 | 第九色 | 在线观看视频免费 | 国产美女在线精品 | 青青草原国产在线观看 | 欧美成人精品一区二区三区 | 国产在线视频99 | 国产精品第56页 | 成人激情五月天 | 国产精品无码av在线播放 | 欧美整片在线观看 | 欧美肉丝袜videos办公室 | 亚洲最大成人在线视频 | 女教师痴汉调教hd中字 | 中文字字幕一区二区三区四区五区 | 韩国明星乱淫(高h)小说 | 激情视频在线免费观看 | 日日摸日日碰夜夜爽av | 超碰人人cao | caoprom97| 日韩成人黄色 | 欧美福利一区二区三区 | 欧美日韩国产专区 | 日韩一区二区在线观看视频 | 亚洲专区av | 亚洲另类网站 | 欧美亚洲久久 | 久久久国产精华液999999 | 污片在线免费观看 | 在线播放日韩av | 精品人妻一区二区色欲产成人 | 天天干网址 | 精品午夜一区二区三区在线观看 | 中文字幕日韩一区二区 | 毛茸茸多毛bbb毛多视频 | 欧美影视一区二区 | 亚洲一区精品视频在线观看 | 无码任你躁久久久久久久 | a在线看| 一本大道久久精品 | 秋霞欧美一区二区三区视频免费 | 男人天堂av在线播放 | 四虎影视成人 | 在线视频你懂得 | 一区二区免费在线视频 | 国产又黄又大又粗的视频 | 欧美男人又粗又长又大 | 精品香蕉一区二区三区 | 欧美一区二区三区小说 | 两口子交换真实刺激高潮 | 青青青国内视频在线观看软件 | 欧美大黄| 国模av在线| 在线永久看片免费的视频 | 可以免费看的黄色 | 我们的2018在线观看免费高清 | 老司机午夜性大片 | 极品销魂美女一区二区三区 | 韩日精品在线 | 日韩五月天| 国产一区二区视频在线播放 | 91视频大全 | 成人a v视频| yjizz视频网 国产乱人对白 | 日韩欧美精品一区二区三区 | 自拍欧美日韩 | 久久久老司机 | a√天堂资源 | 欧美精品一二三 | 91快射 | 依依av| 欧美精品首页 | 欧美日韩偷拍视频 | 亚洲精品粉嫩小泬 | 五月天激情丁香 | yjizz国产 | 欧美成人国产va精品日本一级 | 熟妇人妻久久中文字幕 |