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

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

HDU 5972 Regular Number(ShiftAnd+读入优化)

發(fā)布時(shí)間:2023/11/27 生活经验 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 5972 Regular Number(ShiftAnd+读入优化) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

【題目鏈接】?http://acm.hdu.edu.cn/showproblem.php?pid=5972

?

【題目大意】

  給出一個(gè)字符串,找出其中所有的符合特定模式的子串位置,符合特定模式是指,該子串的長(zhǎng)度為n,并且第i個(gè)字符需要在給定的字符集合Si中?

?

【題解】

  利用ShiftAnd匹配算法。

  bt[i]表示字符i允許在哪些位置上出現(xiàn),我們將匹配成功的位置保存在dp中,那么就可以用dp[i]=dp[i-1]<<1&bt[s[i]]來(lái)更新答案了

  利用滾動(dòng)數(shù)組和bitset可以來(lái)優(yōu)化這樣的運(yùn)算,當(dāng)一個(gè)位置的匹配在更新的過(guò)程中沒(méi)有丟失,

  即始終在特定模式中直到定長(zhǎng),那么這個(gè)位置就是成功匹配位,復(fù)雜度為O(nm/64)

  由于輸入的數(shù)據(jù)量龐大,因此需要讀入和輸出優(yōu)化。

  終于AC了,補(bǔ)上大連賽區(qū)的遺憾。

?

【代碼】

#include <cstdio>
#include <bitset>
#include <cstring>
using namespace std;
const int M=1010,N=5000010,U=256;
bitset<M> dp[2],bt[U];
int n,m,x,id[U],cnt,l;
char s[N];
namespace fastIO{#define BUF_SIZE 100000#define OUT_SIZE 1000000bool IOerror=0;inline char nc(){static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;if(p1==pend){p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);if (pend==p1){IOerror=1;return -1;}}return *p1++;}inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}inline int read(char *s){char ch=nc();for(;blank(ch);ch=nc());if(IOerror)return 0;for(;!blank(ch)&&!IOerror;ch=nc())*s++=ch;*s=0;return 1;}inline int RI(int &a){char ch=nc(); a=0;for(;blank(ch);ch=nc());if(IOerror)return 0;for(;!blank(ch)&&!IOerror;ch=nc())a=a*10+ch-'0';return 1;}struct Ostream_fwrite{char *buf,*p1,*pend;Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;}void out(char ch){if (p1==pend){fwrite(buf,1,BUF_SIZE,stdout);p1=buf;}*p1++=ch;}void flush(){if (p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}}~Ostream_fwrite(){flush();}}Ostream;inline void print(char x){Ostream.out(x);}inline void println(){Ostream.out('\n');}inline void flush(){Ostream.flush();}char Out[OUT_SIZE],*o=Out;inline void print1(char c){*o++=c;}inline void println1(){*o++='\n';}inline void flush1(){if (o!=Out){if (*(o-1)=='\n')*--o=0;puts(Out);}}struct puts_write{~puts_write(){flush1();}}_puts;
};
void init(){cnt=0;for(int i='0';i<='9';i++)id[i]=cnt++;
}
void ShiftAnd(int n,int m){int cur=1,f=0;dp[0].reset(); dp[0].set(0);for(int i=1;i<=n;i++,cur^=1){dp[cur]=dp[cur^1]<<1&bt[id[s[i]]];dp[cur].set(0);if(dp[cur][m]){for(int j=i-m+1;j<=i;j++)fastIO::print(s[j]);fastIO::println();}}
}
int main(){   //freopen("demo.in","r",stdin);//freopen("demo.out","w",stdout);init();while(fastIO::RI(m)){ for(int i=0;i<cnt;i++)bt[i].reset();for(int i=1;i<=m;i++){fastIO::RI(l);for(int j=1;j<=l;j++){fastIO::RI(x);bt[x].set(i);}}fastIO::read(s+1); n=strlen(s+1);ShiftAnd(n,m);}return 0;
}

  

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

總結(jié)

以上是生活随笔為你收集整理的HDU 5972 Regular Number(ShiftAnd+读入优化)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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