int main () {
    int t, ca = 1, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        AC ac;
        for(int i = 0; i < n; ++i) {
            scanf("%s", a);
            ac.insert(a, 1);
        }
        ac.getFail();
        scanf("%d", &n);
        memset(pro, 0, sizeof(pro));
        for(int i = 0; i < n; ++i) {
            char c;
            double p;
            scanf("\n%c%lf", &c, &p);
            pro[ ac.idx(c) ] = p;
        }
        int l;
        scanf("%d", &l);
        for(int i = 0; i < maxnode; ++i) {
            for(int j = 0; j < 110; ++j) dp[i][j] = -1;
        }
        printf("Case #%d: %.6lf\n", ca++, solve(0, l, ac));
    }
    return 0;
}
Пример #2
0
int solve(){
  memset(matchLineCnt, 0, sizeof(matchLineCnt));
  ac.reset();
  for (int i = 0; i < X; i++) ac.insert(patternMat[i], i, Y);
  ac.getFail();
  for (int i = 0; i < N; i++){
    int u = 0;
    for (int j = 0; j < M; j++){
      int c = ac.idx(textMat[i][j]);
      u = ac.ch[u][c];
      for (size_t k = 0; k < ac.val[u].size(); k++){
        int ln = ac.val[u][k];
        if (i - ln >= 0 && j + 1 - Y >= 0){
          matchLineCnt[i - ln][j + 1 - Y]++;
        }
      }
    }
  }
  int total = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      if (matchLineCnt[i][j] == X) total++;
    }
  }
  return total;
}
Пример #3
0
int check_url( string t)
{
	cout<<">>>   URL CHECK   <<<"<<endl;
 //cout<<"enter the strings text"<<endl;
 string url = t;
 //cin>>url;
 int ret_w =  ac_w.checkStrings(url);
 int ret_b =  ac_b.checkStrings(url);
 
 if(ret_w == 1 && ret_b == 2)
{
	cout<<"match white"<<endl;
 	cout<<">>>  URL CHECK END   <<<"<<endl;
	return 1;
}

 if(ret_w == 1 && ret_b == 1)
 {
 	cout<<"match black"<<endl;
 	cout<<">>>  URL CHECK END   <<<"<<endl;
 	return 2;
 }

 if(ret_w == 2 && ret_b == 1)
 {
 	cout<<"match black"<<endl;
 	cout<<">>>  URL CHECK END   <<<"<<endl;
 	return 2;
 }

 if(ret_w == 2 && ret_b == 2)
 {
 	cout << "not in black yet" << endl;
 	cout<<">>>  URL CHECK END   <<<"<<endl;
 	return -1;
 }

}
Пример #4
0
int main(void)
{

    pthread_t pid1, pid2;  
    pthread_mutex_init(&mutex, NULL);  


	printf("---------------------------\n");
	printf("-          START          -\n");
	printf("---------------------------\n");

	load_msg_md5();
	load_msg_ip();
//	load_msg_url_w();
//	load_msg_url_b();
	ac_w.update(0);
	ac_b.update(1);
	load_msg_dns();


    if(pthread_create(&pid1, NULL, func1, NULL))  
    {  
        return -1;  
    }  
  
    if(pthread_create(&pid2, NULL, func2, NULL))  
    {  
        return -1;  
    }  
	
	while(1)
		sleep(0);

	return 0;
	
}
Пример #5
0
int main()
{
    int TC, n_case(0);
    scanf("%d", &TC);
    while(TC--)
    {
        scanf("%d", &SIGMA_SIZE);
        ac.init();
        scanf("%s", str);
        ac.insert(str);
        ac.construct();
        mat.r = ac.size;
        mat.c = ac.size+1;
        mat.reset();
        memset(vis, 0, sizeof(vis));
        dfs(0);
		mat.gaussInt();
		if(n_case)
			cout << "\n";
		cout << "Case " << ++n_case << ":\n";
		cout << mat.arr[0][ac.size] << "\n";
    }
    return 0;
}
Пример #6
0
int main() {
  short nCase;
  scanf("%hd", &nCase);
  for(short iCase = 1; iCase<=nCase; iCase++) {
    short t0;
    ac.clear();
    scanf("%hd", &t0);
    while(t0--) {
      char _[21];
      scanf("%*c%s", _);
      size_t __ = strlen(_);
      for(char *i = _; i!=_+__; i++)
        *i = c2i(*i);
      ac.insertPattern(_, _+__);
    }
    ac.construct();
    scanf("%hd", &t0);
    memset(prob, 0, sizeof(prob));
    while(t0--) {
      char t1;
      scanf("%*c%c", &t1);
      scanf("%lf", prob+c2i(t1));
    }
    scanf("%hd", &t0);
    memset(f, 0, sizeof(f));
    f[0][0] = 1;
    for(int i = 0; i<t0; i++)
      for(short j = 0; j<ac.size(); j++)
        if(f[i][j])
          for(short k = 0; k < 62; k++)
            if(prob[k] && !ac.output(ac.go(j, k)).size())
              f[i+1][ac.go(j, k)] += f[i][j]*prob[k];
    double res = 0;
    for(short j = 0; j<ac.size(); j++)
      res += f[t0][j];
    printf("Case #%hd: %lf\n", iCase, res);
  }
  return 0;
}
double solve(int u, int l, AC &ac) {
    if(l == 0) return 1.0;
    if(dp[u][l] != -1) return dp[u][l];
    double re = 0;
    for(int c = 0; c < sigma_size; ++c) {
        if(pro[c] == 0) continue;
        int ff = u;
        while(ff && !ac.ch[ff][c]) ff = ac.f[ff];
        if(!ac.hasSubStr( ac.ch[ff][c] )) {
            re += pro[c] * solve(ac.ch[ff][c], l-1, ac);
        }
        /*
        if(ac.ch[u][c] && !ac.hasSubStr( ac.ch[u][c] )) {
            re += pro[c] * solve(ac.ch[u][c], l-1, ac);
        } else if(!ac.ch[u][c]) {
            re += pro[c] * solve(0, l-1, ac);
        }
        */
    }
    //printf("%d %d %lf\n", u, l, re);
    return dp[u][l] = re;
}
Пример #8
0
void * func1(void* args)  
{  

	struct msgstru  
	{  
	   int  categary; 
	   char version[2048];  
	  
	};  
	
	int imsgID;
	struct msgstru slQMsg,slRcvMsg;
	int ilrc;
	
	while(1)
	{	
		//pthread_mutex_lock(&mutex);  

		imsgID=msgget(MSGKEY, IPC_EXCL);//检查消息队列是否存在  

		if(imsgID < 0)
		{
		      printf("消息队列不存在! errno=%d [%s]\n",errno,strerror(errno));  
		      exit(-1);  
		}

		ilrc = msgrcv(imsgID,&slRcvMsg,sizeof(struct msgstru),0,0);/*接收消息队列*/  
		
		if ( ilrc < 0 )
		{  
			printf("msgsnd()读消息队列失败,errno=%d[%s]\n",errno,strerror(errno));  
			exit(-1);  
		}
		else
		{
			printf("消息队列read成功\n");
		}
		//free(MSG_R);

		printf("TYPE	=	[%d]\n", slRcvMsg.categary);  
		printf("VERSION	=	[%s]\n", slRcvMsg.version);  
		
		//	 msgctl(imsgID,IPC_RMID,0); //删除消息队列  
		
		printf("---------------------------\n");
		printf("-          UPDATE          \n");
		printf("---------------------------\n");
		
		switch(slRcvMsg.categary)
		{
			case 1:
				load_msg_ip();
				break;
			case 2:
//				load_msg_url_w();
//				load_msg_url_b();
				ac_w.update(0);
				ac_b.update(1);
				break;
			case 3:
				load_msg_dns();
				break;
			case 4:
				load_msg_md5();
				break;
			default:
				printf("The categary type not 1 2 3 4\n");
		}
		
		printf("---------------------------\n");
		printf("-       UPDATE END         \n");
		printf("---------------------------\n");
		
		//pthread_mutex_unlock(&mutex);  
	}
}