http://acm.hdu.edu.cn/showproblem.php?pid=3724
简单字典树 只不过数据处理有点麻烦
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include <iomanip>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=10005;
const int M=2005;
struct node
{
int k;
struct node *next[26];
};
void Add(struct node *head,char stmp[])
{
struct node *w,*t=head;
for(int i=0;stmp[i]!='\0';++i)
{
if(t->next[stmp[i]-'a']==NULL)
{
w=new node;
for(int j=0;j<26;++j)
w->next[j]=NULL;
w->k=0;
t->next[stmp[i]-'a']=w;
}
t=t->next[stmp[i]-'a'];
++(t->k);
}
}
int Fnum(struct node *head,char stmp[])
{
struct node *t=head;
for(int i=0;stmp[i]!='\0';++i)
{
if(t->next[stmp[i]-'a']==NULL)
{
return 0;
}
t=t->next[stmp[i]-'a'];
}
return (t->k);
}
int main()
{
//freopen("data.txt","r",stdin);
char stmp[50];
double a[10];
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
getchar();
struct node *head=new node;
for(int i=0;i<26;++i)
head->next[i]=NULL;
while(n--)
{
gets(stmp);
Add(head,stmp);
}
int ans=0;
while(m--)
{
int k;
scanf("%d",&k);
for(int l=0;l<k;++l)
{
double MIN=INF;
for(int i=0;i<8;++i)
{
scanf("%lf",&a[i]);
MIN=min(MIN,a[i]);
}
int inttmp=0;
for(int i=0;i<8;++i)
{
inttmp*=2;
if(a[i]/MIN>1.5)
inttmp+=1;
}
stmp[l]=inttmp;
}
stmp[k]='\0';
ans+=Fnum(head,stmp);
}
printf("%d\n",ans);
}
return 0;
}
浙公网安备 33010602011771号