思路:
1. 先把那m个排个序 此后每回二分+strncmp一下就好了strncmp是个好东西啊……
2.
hash判判 (注意 hash会有冲突…………………….)//By SiriusRen#include#include #include using namespace std;int n,m,ans;struct Node{ char a[66];}node[10005],jy;bool operator <(Node a,Node b){ return strcmp(a.a,b.a)<=0;} int main(){ scanf("%d%d",&m,&n),getchar(); for(int i=1;i<=m;i++)gets(node[i].a); sort(node+1,node+1+m); for(int i=1;i<=n;i++){ gets(jy.a); int l=1,r=m,len=strlen(jy.a); while(l<=r){ int Mid=(l+r)>>1,judge=strncmp(node[Mid].a,jy.a,len); if(judge<0)l=Mid+1; else if(judge>0)r=Mid-1; else {ans++;break;} } } printf("%d\n",ans);}
//By SiriusRen#include#include #include using namespace std;#define int long longint m,n,f[1111][66],mod=1000000007,ans;char a[1111][66],s[66];signed main(){ scanf("%lld%lld",&m,&n),getchar(); for(int i=1;i<=m;i++)gets(a[i]); for(int i=1;i<=m;i++){ int l=strlen(a[i]); for(int j=0;j